Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to keep hats on the player's character when they die?

Title, how would I do it..? What I have isn't working,

game:GetService('Players').PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			local d = character:GetChildren() 
			for i=1, #d do 
			if (d[i].className == "Accessory") then
				if (d[i]:FindFirstChild("Handle")) then
					local hi=(d[i]:FindFirstChild("Handle"))
					hi.Parent=character
					hi.Anchored=true
					local w = Instance.new('Weld', character)
					w.Part0=hi
					w.Part1=character.Head
					end
				end 
			end
		end)
	end)
end)

1 answer

I've been working on this for a while. The only way I have been able to keep the hat welded after death is to remove the Humanoid. I think the Humanoid keeps force-breaking the welds.

Edit: The Humanoid is definitely the issue. I tried both cloning the previous welds before death and creating new ones and they both work if the Humanoid is destroyed after death. Even if you wait after death for .4 seconds before Destroying the Humanoid, as soon as the Humanoid is destroyed then the welds begin working.

2 comments

0

So you mean to tell me that I have to choose between the clothes and the hats?

0

You could remove the player's head from their character model and then weld the hats. As for removing the Head, you could use the Debris service to remove the Head or use a wait() before destroying it. I'm not sure which one would be more resource efficient, but I'm guessing using Debris.AddItem(, ) would be.

This discussion is preserved as it was. New answers, comments, and votes are closed.