function TeleportPlayerToMap() print("Teleport function works") for i, plr in pairs(AllPlayers) do print(plr.Name) if plr:FindFirstChild("Settings").AFK.Value ~= true then print(plr.Name.."is not AFK") if plr ~= nil then if plr.Character ~= nil then if plr.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) plr.Character.HumanoidRootPart.CFrame = ransp wait() end end end end end end print("Teleport complete") end
So for some reason this script prints "Teleport function works" and "Teleport complete", however it does not teleport the player to the spawns on the map.
function TeleportPlayerToMap() print("Teleport Function Begun") local AllPlayers = game.Players:GetPlayers() local CurrentMap = workspace.CurrentMap -- Change this to the location of "CurrentMap" for i, plr in pairs(AllPlayers) do print(plr.Name) local setting = plr:FindFirstChild("Settings") if setting ~= nil and setting:FindFirstChild("AFK") ~= nil and setting.AFK.Value ~= true then print(plr.Name.." is not AFK") if plr ~= nil and workspace:FindFirstChild(plr.Name) ~= nil and workspace[plr.Name]:FindFirstChild("Humanoid") ~= nil and workspace[plr.Name].Humanoid.Health ~= 0 then local selected = CurrentMap:FindFirstChild("MapSelected") local spawns = nil if selected ~= nil and selected:FindFirstChild("Value") ~= nil and selected.Value:FindFirstChild("Spawns") ~= nil then spawns = selected.Value.Spawns:GetChildren() end if spawns ~= nil then local num = math.random(1, #spawns) local ransp = spawns[num].CFrame + Vector3.new(0, 3, 0) workspace[plr.Name].HumanoidRootPart.CFrame = ransp wait() print("Teleport Complete") end end end end end TeleportPlayerToMap() -- Change this to whatever you want to make the players teleport
So as I said earlier in the comments, the "Teleport Complete" print was only firing once the function was created.
You had a lot of FindFirstChild checks that automatically assumed it was not nil, so I adjusted the if-then clauses to account for these.
The "AllPlayers" calling of players should be inside the function since the players are obviously at some point going to change since the server was created. This is most likely the reason the player's name was not printed.
Since CurrentMap is a StringValue that will likely change, I placed this inside the function as well.
I can see that you haven't called your function for this we need to do:
TeleportPlayerToMap() Below all of the ends.