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

Help with Team.PlayerAdded event?

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)

2 comments

0

is this a script or a localscript

0

What do you see in the output window?

1 answer

  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

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