Script doesn't work (teleport)

the script doesn’t work. The player is supposed to teleport to the map, but this does not happen. No error, the script just doesn’t work

local lobby = game.Workspace.Spawn
local map = game.ReplicatedStorage.Maps:GetChildren()
local status = game.ReplicatedStorage.Status
while true do
	for i = 5, 0, -1 do
		status.Value = "Intermission:"..i
		wait(1)
	end
	local chosenmap = map[math.random(1, #map)]
	local clonemap = chosenmap:Clone()
	clonemap.Parent = game.Workspace
	status.Value = "Map:"..clonemap.Name
	wait(2.5)
	local chosenplayer1 = game.Players:GetPlayers(math.random(1, #game.Players:GetPlayers()))
	local chosenplayer2 = nil
	repeat
		chosenplayer2 = game.Players:GetPlayers(math.random(1, #game.Players:GetPlayers()))
		wait()
	until
	chosenplayer2.Name ~= chosenplayer1.Name
	chosenplayer1.Character.CFrame = clonemap.Teleport1.CFrame
	chosenplayer2.Character.CFrame = clonemap.Teleport2.CFrame
	for i = 10, 0, -1 do
		status.Value = "Liquidation:"..i
		wait(1)
	end
	local chosenplayer1 = game.Players:GetPlayers(math.random(1, #game.Players:GetPlayers()))
	local chosenplayer2 = nil
	repeat
		chosenplayer2 = game.Players:GetPlayers(math.random(1, #game.Players:GetPlayers()))
		wait()
	until
	chosenplayer2.Name ~= chosenplayer1.Name
	chosenplayer1.Character.CFrame = clonemap.Teleport1.CFrame
	chosenplayer2.Character.CFrame = clonemap.Teleport2.CFrame
	clonemap:Destroy()
	end
2 Likes

maybe it’s the 16th line?repeat chosenplayer2 = game.Players:GetPlayers(math.random(1, #game.Players:GetPlayers())) wait()

May I ask a few questions about your code?

  1. There will only be two players right?
  2. Why are you destroying the map after you teleport them to it?
    When does the code stop working?

When teleporting the players, you should use-
chosenplayer1.Character:PivotTo(clonemap.Teleport1.CFrame)
chosenplayer2.Character:PivotTo(clonemap.Teleport2.CFrame)

why I can’t use CFrame? When i did TeleportParts i used Cframe

it doesn’t work :slightly_frowning_face: How can I solve this problem?

Character.CFrame doesn’t work as Character is a model. Instead, please use Character:MoveTo()

it doesn’t work again. I don’t know what the problem is

Because the character is a model, it doesn’t have the cframe property the same way parts and meshes do

local lobby = game.Workspace.Spawn
local map = game.ReplicatedStorage.Maps:GetChildren()
local status = game.ReplicatedStorage.Status
while true do
	for i = 5, 0, -1 do
		status.Value = "Intermission:"..i
		wait(1)
	end
	local chosenmap = map[math.random(1, #map)]
	local clonemap = chosenmap:Clone()
	clonemap.Parent = game.Workspace
	status.Value = "Map:"..clonemap.Name
	wait(2.5)
	local chosenplayer1 = game.Players:GetPlayers(math.random(1, #game.Players:GetPlayers()))
	local chosenplayer2 = nil
	repeat
		chosenplayer2 = game.Players:GetPlayers(math.random(1, #game.Players:GetPlayers()))
		wait()
	until
	chosenplayer2.Name ~= chosenplayer1.Name
	chosenplayer1.Character.CFrame = clonemap.Teleport1.CFrame
	chosenplayer2.Character.CFrame = clonemap.Teleport2.CFrame
	for i = 10, 0, -1 do
		status.Value = "Liquidation:"..i
		wait(1)
	end
	local chosenplayer1 = game.Players:GetPlayers(math.random(1, #game.Players:GetPlayers()))
	local chosenplayer2 = nil
	repeat
		chosenplayer2 = game.Players:GetPlayers(math.random(1, #game.Players:GetPlayers()))
		wait()
	until
	chosenplayer2.Name ~= chosenplayer1.Name
	chosenplayer1.Character:MoveTo(clonemap.Teleport1.Position)
	chosenplayer2.Character:MoveTo(clonemap.Teleport2.Position)
	clonemap:Destroy()
	end

I changed cframe to moveto, but nothing works, and the main thing is that there is no error either

Use my script above, it should work

nothing happens. I think I just made some stupid mistake and I can’t figure it out

Also, are you sure there are two people? From what I’ve seen, the script doesn’t continue unless there is at least 2 players

there is no error, the script does not work either

Try debugging it and adding a print statement before the loop, in the loop, and in the for loop

i think your getplayers thing is wrong

game.Players:GetPlayers(math.random(1, #game.Players:GetPlayers()))

because when you get the players it returns a table of the players and their index
so you do it like this i think

game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]

also this is what i would do if i were writing it:

local lobby = game.Workspace.Spawn
local map = game.ReplicatedStorage.Maps:GetChildren()
local status = game.ReplicatedStorage.Status
while true do
	for i = 5, 0, -1 do
		status.Value = "Intermission:"..i
		wait(1)
	end
	local chosenmap = map[math.random(1, #map)]
	local clonemap = chosenmap:Clone()
	clonemap.Parent = game.Workspace
	status.Value = "Map:"..clonemap.Name
	wait(2.5)
	local chosenplayer1 = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
	local chosenplayer2 = nil
	repeat
                wait()
		chosenplayer2 = game.Players:GetPlayers(math.random(1, #game.Players:GetPlayers()))
	until chosenplayer2 ~= chosenplayer1
	chosenplayer1.Character:PivotTo(clonemap.Teleport1.CFrame)
	chosenplayer2.Character:PivotTo(clonemap.Teleport2.CFrame)
	for i = 10, 0, -1 do
		status.Value = "Liquidation:"..i
		wait(1)
	end
	clonemap:Destroy()
	end