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

This removes the hat when the player dies?

I have a script that adds a hat to the character depending on the team they are on, but if the player dies or resets, the hat is gone. this is the script: (no errors)

game.Players.PlayerAdded:connect(function(p)
 p.CharacterAdded:connect(function(c)
		if p.TeamColor == BrickColor.new("Bright blue") then
         p.CanLoadCharacterAppearance = false
         p.CharacterAdded:wait()
         local char = p.Character
         local blue = game.ServerStorage.BlueTeam:Clone()
         blue.Parent = c
         char.Torso.BrickColor = BrickColor.new("Bright blue")
     elseif p.TeamColor == BrickColor.new("Bright red") then
         p.Neutral = false
         p.TeamColor = BrickColor.new("Bright red")
     p.CanLoadCharacterAppearance = false
     p.CharacterAdded:wait()
     local char = p.Character
     local red = game.ServerStorage.RedTeam:Clone()
     red.Parent = c
    char.Torso.BrickColor = BrickColor.new("Bright red")
    end
 end)
end)

1 answer

Because this is only running when they join and only when they join, use a CharacterAdded function. If that's not your issue, I suggest adding it within your alleged hat script as well.

game.Players.PlayerAdded:connect(function(p)
 p.CharacterAdded:connect(function(c)
     local chance = math.random(1, 2)
     if chance == 1 then
         p.Neutral = false
         p.TeamColor = BrickColor.new("Bright blue")
         p.CanLoadCharacterAppearance = false
         p.CharacterAdded:wait()
         local char = p.Character
         local blue = game.ServerStorage.BlueTeam:Clone()
         blue.Parent = char
         char.Torso.BrickColor = BrickColor.new("Bright blue")
     elseif chance == 2 then
         p.Neutral = false
         p.TeamColor = BrickColor.new("Bright red")
     p.CanLoadCharacterAppearance = false
     p.CharacterAdded:wait()
     local char = p.Character
     local red = game.ServerStorage.RedTeam:Clone()
     red.Parent = char
    char.Torso.BrickColor = BrickColor.new("Bright red")
    end
 end)
end)

Sorry about the messy tabbing, I did it on the site and had to use space (...?)

4 comments

0

no errors appear but it doesn't add the hat to the character at all now

0

Could you post your hat-giving script?

0

It's what I posted

0

You haven't demonstrated use of hats.

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