function Start() local Teams = game:GetService("Teams") local Point1 = game.Workspace.Point1 local teamAlpha = Teams.Alpha local teamSpectator = Teams.Spectator for _, player in pairs(game.Players:GetChildren()) do if player.Team == teamSpectator then local Player1 = (player[math.random(1, #player)]) Player1.Team = teamAlpha Player1.TeamColor = teamAlpha.TeamColor Player1.CharacterAdded:Connect(function(character) character.GetPropertyChangedSignal("Parent"):Wait() wait() character.HumanoidRootPart.CFrame = Point1.CFrame end) print(Player1.. "joined the round") end Start()
I know problem in #player but I don't know how to fix it. I need to pick random player and if he in team "Spectator" he gonna to join teamAlpha. But when I try to pick random player error pops-out
RoundScript:12: attempt to get length of local 'player' (a userdata value)
function Start() local Teams = game:GetService("Teams") local Point1 = game.Workspace.Point1 local teamAlpha = Teams.Alpha local teamSpectator = Teams.Spectator if player.Team == teamSpectator then local Player1 = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())] Player1.Team = teamAlpha Player1.TeamColor = teamAlpha.TeamColor Player1.CharacterAdded:Connect(function(character) character.GetPropertyChangedSignal("Parent"):Wait() wait() character.HumanoidRootPart.CFrame = Point1.CFrame end) print(Player1.. "joined the round") Start()