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

How do you check what team a player is on using an "if" statement?

I'm having trouble with this:

game.Players.PlayerAdded:connect(function(player)
		if player.Teams == Spectators then
			player.CameraMode = "LockFirstPerson"
		end
end)

Thanks in advance!

2 answers

✓ Accepted answer
function getTeamsColorFromName(name)
	local color
	for _,v in pairs(game.Teams:GetChildren()) do
		if v.Name == name then
			color = v.TeamColor
		end
	end
	return color
end

game.Players.PlayerAdded:connect(function(player)
	repeat wait() until player ~= nil -- This event is not very trust-worthy.
	if player.TeamColor == getTeamColorFromName("Spectators") then
		player.CameraMode = "LockFirstPerson"
	end
end)

Broken down, the function at the top returns the Team's TeamColor from the name of it (Spectators) and then sets their CameraMode.

game.Players.PlayerAdded:connect(function(player)
        if player.Teams == "Spectators" then
            player.CameraMode = "LockFirstPerson"
        end
end)

That should work? I can't test it, RobloxStudio crashes every 1 minute for me.

1 comment

0

Don't use Studio's script editor. It crashes your game. Download Notepad++ and just copy + paste whenever you want to edit or something :p

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