How do i teleport all players to a diffrent game on button press

I have this script, but it doesnt work. I have been researching this and cant find the awnser that would work.

script.Parent.MouseButton1Click:Connect(function()
if workspace.Map.Value == "StreetCorner" then
	local gameid = (my game id in here)
	for _,p in pairs(game.Players:GetPlayers()) do
		game:GetService('TeleportService'):Teleport(gameid,p)
	end
end

end)

its in a localscript, also i tried it in a normal script.
It only teleports the 1 player who pressed the button

The TeleportService doesn’t work in Studio, nor does it work in a LocalScript.

yeah i know i realized teleportPartyAsync exists

Use a RemoteEvent instead, which will fire a request from the client to the server, in order to teleport all the Players using the Teleport function from the server-side

--Local Side
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

script.Parent.MouseButton1Down:Connect(function()
    if workspace.Map.Value == "StreetCorner" then
	    Event:FireServer()
    end
end)
--Server Script inside ServerScriptService
local gameid = (my game id in here)
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function()
	for _,p in pairs(game.Players:GetPlayers()) do
		game:GetService('TeleportService'):Teleport(gameid,p)
	end
end)
1 Like