The reason for the error is because you've got two for loops in your script, looping through each player in the game. In your script, you're basically telling the computer to do is to teleport all the players if a player's AFK value is true.
To fix this, you only need to get rid of one of the for loops and either one of the two ends at the bottom of your script, depending on which for loop you remove. You will then need to modify your script appropriately so that it will fit the for loop you've chosen to keep.
If you choose to remove the first for loop surrounding the other for loop, your script will look like this:
Spawns = game.Workspace:WaitForChild("Spawns")
for _, Player in pairs(game.Players:GetPlayers()) do
if Player:WaitForChild("AFK").Value == true then
local char = Player.CharacterAdded:wait()
char:WaitForChild("Torso").CFrame = Spawns[_G.StartingPlaces[math.random(1,#_G.StartingPlaces)]].CFrame * CFrame.new(0,8,0)
end
end
If you choose to remove the second for loop, your script will look like this:
Spawns = game.Workspace:WaitForChild("Spawns")
Players = game.Players:GetPlayers()
for PlayerTeleport = 1, #Players do
if Players[PlayerTeleport]:WaitForChild("AFK").Value == true then
local char = Players[PlayerTeleport].CharacterAdded:wait()
char:WaitForChild("Torso").CFrame = Spawns[_G.StartingPlaces[math.random(1,#_G.StartingPlaces)]].CFrame * CFrame.new(0,8,0)
end
end
I hope my answer helped you. If it did, be sure to accept it.
2 comments
You already have a check on line 8...
Yeah, I have the check but the function for teleporting works on everyone, not just that player