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

Help with Team.PlayerAdded event?

Asked by 3 years ago

The text for this isnt changing. I dont know if im using the team.PlayerAdded event wrong.

game.Teams.Red.PlayerAdded:Connect(function(player)
    if player.Team = game.Teams.Blue then
        script.Parent.Text = "Protect this statue!"
    end
end)

game.Teams.Red.PlayerAdded:Connect(function(player)
    if player.Team = game.Teams.Blue then
        script.Parent.Text = "Attack this statue!"
    end
end)
0
is this a script or a localscript brokenVectors 525 — 3y
0
What do you see in the output window? gskw 1046 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago
  1. You're checking if the player is on the Blue team when he's joined the Red team, which makes no sense.

  2. The teams don't replicate to the client instantly, so you'll want to use WaitForChild instead.

  3. You shouldn't be indexing Services directly, instead use GetService.

Solution:

local teams = game:GetService('Teams')
local red = teams:WaitForChild("Red")
local blue = teams:WaitForChild("Blue")
red.PlayerAdded:Connect(function(player)
    if player.Team == red then
        script.Parent.Text = "Protect this statue!"
    end
end)

blue.PlayerAdded:Connect(function(player)
    if player.Team == blue then
        script.Parent.Text = "Attack this statue!"
    end
end)

Hope this helped

Ad

Answer this question