p = game.Players.LocalPlayer
char = p.Character
Storage = game:GetService("ServerStorage") --Using :GetService() because the script can cause an error if used in multiplayer(uploaded to roblox) when not calling the service
script.Parent.MouseButton1Down:connect(function()
local cont = char:GetChildren()
for i,v in pairs(cont) do -- Removing all other hats
if v:IsA("Hat") then
v:Destroy()
end
end
local hat = Storage.HATNAME:clone() --HATNAME is just a template for other hats in serverstorage
hat.Parent = char
hat.Name = "Hat"
end)
--Also how could this be done with multiple hats?
COMMUNITY QUESTION
Why won't this script put the hat on the player? Instead the hat just falls off. (UNANSWERED)
1 answer
I already Answered this question here. Look at the edit section.
player = game.Players.LocalPlayer
h = player.Character.Head
script.Parent.MouseButton1Down:connect(function()
if not h.face.Texture == "http://www.roblox.com/asset/?id=138224650" then
h.face:Destroy()
for _,v in pairs(player.Character:GetChildren()) do --Get all the children
if v.ClassName == "Hat" then --If it's a hat
v:Destroy() --Destroy
for _,i in pairs(game.ServerStorage:GetChildren()) do --Get all the hats in serverstorage.
if i.ClassName == "Hat" then
i:clone().Parent = player.Character --Make the hat's go inside the character
player.Character:MakeJoints() --MAKE JOINTS!!!
end
end
end
end
local newface = Instance.new("Decal",h)
newface.Name = "face"
newface.Texture = "http://www.roblox.com/asset/?id=138224650"
end
end)
I told you to make joints! Use the :MakeJoints() function! Use this function to make the hat stay on your head!
2 comments
0
It is not working. I got the face to work but not the hat. I give up. I have asked this question for over a year to many. It just won't work.
0
MakeJoints won't attach hats.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
But the problem is with the script from the other guy, ArduinoUNO, it had 2 errors in it. It can be done with multiple hats, it can stick to the player, and it does work. It works for me. Does it work in online mode? It works in solo mode.
Lord what hat are you using and is it a local script?
I just get random hats. It is indeed local.