Teleport doesn't work?

So I made this Script that after the Intermission the player gets teleported to an Island but as soon as the Intermission hits 0 it doesn’t work?


local RoundLength = 90 
local IntermissionLength = 15
local InRound = game.ReplicatedStorage.inRound
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.map.SpawnLocation
local GameAreaSpawn = game.Workspace.map.islands.i1

InRound	.Changed:Connect(function()
	wait(1)
	if InRound.Value == true then
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = GameAreaSpawn.CFrame
		end
	else
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
		end
	end
end)



local function RoundTimer()
	while wait() do
		for i = IntermissionLength, 1, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Intermission: ".. i .. " seconds left!"
		end
		for i = RoundLength, 1, -1 do
			InRound.Value = true
			wait(1)
			Status.Value = "Game: ".. i .." seconds left!"
		end
	end
end

spawn(RoundTimer)
1 Like

Try this out:

local RoundLength = 90 
local IntermissionLength = 15
local InRound = game.ReplicatedStorage.inRound
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.map.SpawnLocation
local GameAreaSpawn = game.Workspace.map.islands.i1

InRound	.Changed:Connect(function()
	wait(1)
	if InRound.Value == true then
		for _, player in ipairs(game.Players:GetChildren()) do
			local char = player.Character
			
			if char then
				char:PivotTo(GameAreaSpawn.CFrame)
			end
		end
	else
		for _, player in ipairs(game.Players:GetChildren()) do
			local char = player.Character
			
			if char then
				char:PivotTo(LobbySpawn.CFrame)
			end
		end
	end
end)

still doesn’t work tho idk why

local RoundLength = 90 
local IntermissionLength = 15
local InRound = game.ReplicatedStorage.inRound
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.map.SpawnLocation
local GameAreaSpawn = game.Workspace.map.islands.i1

InRound	.Changed:Connect(function()
	wait(1)
	if InRound.Value == true then
		for _, player in ipairs(game.Players:GetChildren()) do
			local char = player.Character

			if char then
				char:PivotTo(GameAreaSpawn.CFrame)
			end
		end
	else
		for _, player in ipairs(game.Players:GetChildren()) do
			local char = player.Character

			if char then
				char:PivotTo(LobbySpawn.CFrame)
			end
		end
	end
end)



local function RoundTimer()
	while wait() do
		for i = IntermissionLength, 1, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Intermission: ".. i .. " seconds left!"
		end
		for i = RoundLength, 1, -1 do
			InRound.Value = true
			wait(1)
			Status.Value = "Game: ".. i .." seconds left!"
		end
	end
end

spawn(RoundTimer)

If you’re testing in studio, it may be because you can’t teleport in studio, try publishing and then testing in the real game

Just a few tips for you: Maybe fixing and doing this will make it work.
When accessing things in the ReplicatedStorage service, make sure to use :WaitForChild() on the objects you’re getting, in case these have not loaded into the game yet.

When you’re looping through the players in the game, note that using ipairs() is different from pairs(), in that ipairs() stops the loop when it reaches a nil value.

I dont really do much scripting with characters, but the line where the char variable is being created. Iwould make it:

local char = game.Workspace:FindFirstChild(player.Name)

Also, does anyone want to explain what the :PivotTo() method does? Never seen this method before.

1 Like

AHA! This might be the fix, but in the RoundTimer() function, inside the while wait() do, where the
for loops are, you’re setting the value of InRound to be false when the intermission starts counting down, and remeber, at the top of your script, you’re checking to see if the InRound has a value of true. If it has a value of true, then all the players go to the “island”. Every second you’re checking if it false or if it is true.

But since you’ve added an else in that if statement, if inRound.Value = false, then everyone gets sent right back to the lobby.

Also, threads might be a problem too.

local function RoundTimer()
	while wait() do
		for i = IntermissionLength, 1, -1 do
			InRound.Value = false -- If false, everyone goes to the lobby. Change it to be = true
			wait(1)
			Status.Value = "Intermission: ".. i .. " seconds left!"
		end
		for i = RoundLength, 1, -1 do
			InRound.Value = true -- Change this to false
			wait(1)
			Status.Value = "Game: ".. i .." seconds left!"
		end
	end
end
1 Like