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

What am I doing wrong?(Still unanswered)

Asked by
wjs3456 90
10 years ago

Ok so I made it so that my you started out on one team but if you were killed then it would take you to the other. And that worked. But then I realized since I wanted the map/players to reset after the round that they would only be on the right team once(the first time they spawned) So this is my script to make it spawn on the blue team every time the round began but it didn't work.

function respawn()
for i,v in pairs(game.Players:GetPlayers()) do
    v.Character.Humanoid.Health = 0
game.Players.PlayerAdded:connect(function(p)
p.CharacterAdded:connect(function(c)
c:WaitForChild("Humanoid").Died:connect(function()
p.TeamColor = BrickColor.new("Bright Blue")
end)
end)
end)
c:WaitForChild("Humanoid").Died:connect(function()
p.TeamColor = BrickColor.new("Bright Orange") 
end)
end

Any help. Thanks

0
Does it make the players change to the orange team instead? RedCombee 585 — 10y
0
It would usually change them to orange once they die but I dont want that to happen when it resets the map. wjs3456 90 — 10y

1 answer

Log in to vote
0
Answered by
RedCombee 585 Moderation Voter
10 years ago

The issue to your problem is that you have two functions that determine the team the player joins on death of the humanoid. This causes the "Bright Orange" function to run after the "Bright Blue" function. the easiest way to work around this is to simply replace:

c:WaitForChild(Humanoid).Died:connect(function()
p.TeamColor = BrickColor.new("Bright blue")
end)

With:

p.TeamColor = BrickColor.new("Bright blue")

"Blue" and "Orange" also cannot be capitalized.

0
What do you mean by add in the respawn function? wjs3456 90 — 10y
Ad

Answer this question