Trying to teleport all players for a star wars shooter game. The following function gives the error attempt to index nil with 'HumanoidRootPart'.
Any help?
(I have already tried a WaitForChild, that returned the same error but with WaitForChild rather than HumanoidRootPart.)
for _, player in pairs(game.Players:GetChildren()) do
if player.Team ~= game.Teams.Lobby then
player.Character.HumanoidRootPart.CFrame = Spawns[math.random(1,#Spawns)].CFrame
player.Character.Humanoid.WalkSpeed = 0
end
end

2 comments
Try using "game.Players:GetPlayers()" There may be something in "game.Players" that isn't a player
Just a suggestion, instead of using HumanoidRootPart.CFrame use Character:SetPrimaryPartCFrame("Insert CFrame Here")