local gameSpawn = game.Workspace.gameSpawn local lobbySpawn = game.Workspace.Lobby.lobbySpawn.lobbySpawn local minimumGameSpawn = 1 local minimumLobbySpawn = 4 function teleportPlayers(target) for _, player in pairs(game.Players:GetChildren()) do local character = player.Character local torso = character.Torso torso.CFrame = target.CFrame end end wait(5) print("Racers To Your Karts") wait(2) teleportPlayers(gameSpawn)
Also its fine when i test this by myself in solo mode or play mode but when i test this in test mode from the clients and servers area to where you can test with multiple people you can control with different windows, IT DOESNT teleport them. Please help
For the teleporting players, you're basically passing a table as an argument to the function. Here's how I'd set it up:
local targets = {} --Either a table or a model of the parts you want to teleport players to. If it's a model, then define it as model:GetChildren() local function teleport(targets) local targets = targets --Defines targets as local so that manipulating the table in the loop doesn't effect the one outside the function for i,v in ipairs(game.Players:GetChildren()) do --ipairs is a lot like pairs, except it stops iterating if it finds a nil value in the table local ran = math.random(1,#targets) --returns a random number bewteen 1 and the length of the table pcall(function() v.Character.HumanoidRootPart.CFrame = targets[ran].CFrame end) --pcall runs a function in safemode, so if it results in an error, it keeps running the following code. It also returns a bool and an error message. I used an anonymous function in it, so that I don't have to redefine one every time we call the function in the loop. table.remove(targets,ran)--removes the target from targets to prevent players from being teleported to the same target end--end loop end--end function for i = 20,0,-1 do --countdown to give players time to join, optional. wait(1) print(i) end teleport(targets)--calls the function