I'm making a teleport script (function totolobby()) in a localscript, but it only teleports once, but not twice.
Same for removing the map (function unloadmap()) .
Script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local lobbylocation = CFrame.new(math.random(4066,4114),7.5,math.random(84,182))
local tpBackToLobbyEvent = ReplicatedStorage:WaitForChild("TpBackToLobby")
function tptolobby()
for i, player in pairs(game.Players:GetChildren()) do
if player.Character:FindFirstChild("HumanoidRootPart") then
player.Character.HumanoidRootPart.CFrame = lobbylocation
end
end
end
function unloadMap()
if game.Workspace:FindFirstChild("Map") then
game.Workspace.Map:Destroy()
end
end
function onTpBackToLobby()
print("BackToLobby")
tptolobby()
unloadMap()
end
tpBackToLobbyEvent.OnClientEvent:Connect(onTpBackToLobby)

2 comments
You never told it to run twice. You will need to loop it, or find a reason to make it run again
Actually, this issue was solved yesterday by putting the activator script to another location, but thanks for the explanation!