Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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

Log in to vote
0
Answered by
Yionee 65
7 years ago
Edited 7 years ago

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.

0
So you mean to tell me that I have to choose between the clothes and the hats? MmC00KIESmM 5 — 7y
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(<Item>, <Time>) would be. Yionee 65 — 7y
Ad

Answer this question