I've tried making so when a specific player (let's say me) enters the game, a script will put a hat on their head. It's like Ontouch but without touching it. And when you die the script will re-add the hat(s) back onto you. This have been troubling me for weeks and I cannot seem to find the answer, does anyone know of a script that could make this work ? Much obliged if you can figure it out!
I already have this default script I always start from but keep getting nowhere with it.
debounce = true
function onTouched(hit)
if (hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == true) then
debounce = false
h = Instance.new("Hat")
p = Instance.new("Part")
h.Name = "CinnamonHair"
p.Parent = h
p.Position = hit.Parent:findFirstChild("Head").Position
p.Name = "Handle"
p.formFactor = 0
p.Size = Vector3.new(1, 2.4, 2)
p.BottomSurface = 0
p.TopSurface = 0
p.Locked = true
script.Parent.Mesh:clone().Parent = p
h.Parent = hit.Parent
h.AttachmentForward = Vector3.new(-0, -0.0995, -0.995)
h.AttachmentPos = Vector3.new(0, 0.9, 0)
h.AttachmentRight = Vector3.new(1, 0, 0)
h.AttachmentUp = Vector3.new(0, 0.995, -0.0995)
wait(5)
debounce = true
end
end
script.Parent.Touched:connect(onTouched)
I was thinking you could replace "onTouched" with a player detect with a player id or name associated with it. If that's possible?

3 comments
@thecanadiangamesnerd I've tried multiple ways to make this work ingame and it still doesn't work :(
function onPlayerAdded(newplayer) if newplayer.Name == "EastHalo0" then debounce = false h = Instance.new("Hat") p = Instance.new("Part") h.Name = "CinnamonHair" p.Parent = h p.Position = hit.Parent:findFirstChild("Head").Position p.Name = "Handle" p.formFactor = 0 p.Size = Vector3.new(1, 2.4, 2) p.BottomSurface
Replace any "hit.Parent" with "newplayer.Character". That should do it. The only thing that happens currently is the script tries to position the hat over a nonexistant hit.parent. Enjoy!