I previously tried to use this but it doesn't work
for i,v in pairs(game.Players:GetPlayers()) do v.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.tp) end
I need to be able to teleport all players to a map once its loaded and back when the map is unloaded/round is over but my teleport script doesnt seem two work
while true do local map = math.random(1, 4) if map == 1 then local gamespawn = game.Lighting.Map1.SpawnLocation local m = Instance.new("Message", game.Workspace) m.Text = "map1test" wait(3) ------------------------------ -- Code where all players get teleported into map ------------------------------ m:Destroy() local Map1copy = game.Lighting.Map1:clone() Map1copy.Parent = game.Workspace wait(4) ------------------------------ -- Code where all the players get teleported back to the lobby ------------------------------ Map1copy:Destroy() elseif map == 2 then local m = Instance.new("Message", game.Workspace) m.Text = "map2test" wait(3) ------------------------------ -- Code where all players get teleported into map ------------------------------ m:Destroy() local Map2copy = game.Lighting.Map2:clone() Map2copy.Parent = game.Workspace wait(4) ------------------------------ -- Code where all the players get teleported back to the lobby ------------------------------ Map2copy:Destroy() elseif map == 3 then local m = Instance.new("Message", game.Workspace) m.Text = "map3test" wait(3) ------------------------------ -- Code where all players get teleported into map ------------------------------ m:Destroy() local Map3copy = game.Lighting.Map3:clone() Map3copy.Parent = game.Workspace wait(4) ------------------------------ -- Code where all the players get teleported back to the lobby ------------------------------ Map3copy:Destroy() elseif map == 4 then local m = Instance.new("Message", game.Workspace) m.Text = "map4test" wait(3) ------------------------------ -- Code where all players get teleported into map ------------------------------ m:Destroy() local Map4copy = game.Lighting.Map4:clone() Map4copy.Parent = game.Workspace wait(4) ------------------------------ -- Code where all the players get teleported back to the lobby ------------------------------ Map4copy:Destroy() end end
You didnt set each player's HumanoidRootPart CFrame to your tp part CFrame, so it'll error and :clone()
and the parent parameter of Instance.new()
is deprecated. Instead set the parent last of the Instance and use :Clone()
.
for _,v in pairs(game.Players:GetPlayers()) do v.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.tp.CFrame.Position) end