Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Teleporting script only teleporting one player, instead of certain ones?

My teleporting script is suppose to teleport everyone, but it's only teleporting the player who clicked. Not sure why its doing this, is there an error?

local remote = game.ReplicatedStorage.StartEvent
remote.OnServerEvent:Connect(function(player)
	for i, v in pairs(game.Players:GetPlayers()) do
		local bool = v:FindFirstChildOfClass("BoolValue")
		local frame = v.PlayerGui.ActiveLobbys.Frame.Frame.Frame
		local player2 = frame.PlayerName.Text
		local gameplaceid = 3313994275
		local Player = player
		local PlayersToTeleport = {}
		local AlreadyInTable = false

			for _,OtherPlayer in next,PlayersToTeleport do
				if OtherPlayer == Player then
				AlreadyInTable = true
			end
		end
		if not AlreadyInTable then
			table.insert(PlayersToTeleport,Player)
		end

			local TeleportService = game:GetService("TeleportService")
			local Reserve = TeleportService:ReserveServer(3313994275)
	 
			TeleportService:TeleportToPrivateServer(gameplaceid, Reserve, PlayersToTeleport)
    end
end)

1 answer

✓ Accepted answer

Here this should help:

local TeleportService = game:GetService("TeleportService")
local Reserve = TeleportService:ReserveServer(3313994275)
for i,v in pairs(game.Players:GetChildren()) do
        table.insert(PlayerToTeleport,i,v.Name)
 end
for i,v in pairs(PlayersToTeleport) do
	TeleportService:TeleportToPrivateServer(gameplaceid, Reserve, PlayerToTeleport[v])
end

You should've called the TeleportService and the Reserve variables at the start of the script to avoid changing lines etc. What I did here is that I looked how much player's there where, and teleported each player 1 by 1 in a for i,v loop.

5 comments

0

Unable to cast value to objects line 9?

0

Edited the showcase in my response. Hopefully this works..?

0

I already changed it to work, but Ill try this.

0

The v doesn't work in the teleporting part.

0

I just erased it.

This discussion is preserved as it was. New answers, comments, and votes are closed.