In the game I am creating the script has multiple functions to create one streamlined function, one of which handles teleporting players to the starting zone of the map. However, it is suppose to grab only those whose notready.Value = false which is located inside of a folder in the player but when two people have it set to that it only grabs the first one to join the game leaving the other left behind. Then when the game is over and the player who got into the map their notready.Value is reset to true; however, the player left behind stays false but the game won't register them as a player that is ready. It is not a local script and the NotReady value is inside a folder created inside of all players.
Here is the code with the variables to go with it:
local Players = game:GetService("Players") local AllPlayers = Players:GetChildren() function TeleportPlayerToMap() for i = 1,#AllPlayers do if AllPlayers[i]:WaitForChild("Settings").NotReady.Value ~= true then if AllPlayers[i] ~= nil then if AllPlayers[i].Character ~= nil then if AllPlayers[i].Character:FindFirstChild("Humanoid").Health ~= 0 then local spawns = CurrentMap:FindFirstChild(MapSelected.Value):FindFirstChild("Spawns"):GetChildren() if spawns ~= nil then local ransp = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,3,0) AllPlayers[i].Character.HumanoidRootPart.CFrame = ransp wait() if AllPlayers[i] ~= nil then if AllPlayers[i].Character ~= nil then AllPlayers[i].Character.HumanoidRootPart.CFrame = ransp end end wait() if AllPlayers[i] ~= nil then if AllPlayers[i].Character ~= nil then AllPlayers[i].Character.HumanoidRootPart.CFrame = ransp end end end end end end end end end
local players = game:GetService("Players"):GetPlayers() function teleportPlayers() for _, v in pairs(players) do if v.Character and not v.Settings.NotReady.Value then v.Character.HumanoidRootPart.CFrame = -- CFrame coding here end end end