KrypticonJoin Date: 2014-02-12 Post Count: 680 |
Basically I just want to know how to make it so that the player can't throw their hat's of. Thanks :) |
|
blockooJoin Date: 2007-11-08 Post Count: 17202 |
You can't "disable" it, but you can make a script that puts the hat right back on the player's head the instant that they drop it. |
|
blockooJoin Date: 2007-11-08 Post Count: 17202 |
|
|
MHebesJoin Date: 2013-01-04 Post Count: 2278 |
Aw you ninja'd me. Here's my take, anyways (LocalScript in StarterGui)
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
local hats = {}
for _, hat in pairs(character:GetChildren()) do if hat:IsA("Hat") then table.insert(hats, hat) end end
character.ChildAdded:connect(function(hat) if hat:IsA("Hat") then table.insert(hats, hat) end end)
game:GetService("RunService").RenderStepped:connect(function()
for _, hat in pairs(hats) do
if hat.Parent ~= character then
hat.Parent = character
end
end
end) |
|
MHebesJoin Date: 2013-01-04 Post Count: 2278 |
(I lied you didn't ninja me I just wanted to do it) |
|
blockooJoin Date: 2007-11-08 Post Count: 17202 |
Th original one I published had a bug, which I fixed in the newest version.
@MHebes
Wow, I didn't even thing about using a LocalScript in StarterGui :P Still, mine works upon being inserted into Workspace and runs off of only a single script for all players. |
|
MHebesJoin Date: 2013-01-04 Post Count: 2278 |
It also creates a new thread for each player :P
Also, I suggest using RunService.RenderStepped instead of a while loop - it runs at 60 FPS instead of 30, meaning you don't see the hat flicker off. |
|
blockooJoin Date: 2007-11-08 Post Count: 17202 |
Thanks for the suggestion. I also just found a major problem with my script, and I assume it is for yours as well. Every time the function plays through, it adds the same hat to the table over and over and the game gets extremely laggy very quickly. |
|
blockooJoin Date: 2007-11-08 Post Count: 17202 |
Ok, final version for sure this time. I have fully updated and fixed the script in the link I posted above. |
|
KrypticonJoin Date: 2014-02-12 Post Count: 680 |
Thanks guys :D |
|
Brick_manJoin Date: 2009-11-20 Post Count: 5634 |
I know the problem is solved now, but I thought there was a way to disable keys. I think the method was :UnbindKey or something like that. |
|
KrypticonJoin Date: 2014-02-12 Post Count: 680 |
Cool, good to know thanks :) |
|
|
Or if you don't want to use while loops or run service:
Game.Players.PlayerAdded:connect(function(P)
P.CharacterAdded:connect(function(C)
C.DescendantRemoving:connect(function(D)
if D:IsA("Hat") then
D.Parent = C
end
end)
end)
end) |
|