Does anyone have any idea for how I can get "player"?

Hey Roblox devs. I have a teleport system in my game and I was adding player data for when the player teleports, but I came across a problem.

local function teleportPlayers()
	if #list > 0 then
		billboard.Frame.Status.Text = "TELEPORTING"
		billboard.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
		local playersToTeleport = {}

-- This part 🡣
		local TPdata = {
			Coins = player.leaderstats.Coins.Value,
			XP = player.leaderstats.XP.Value,
			Level = player.Level.Value,
			Rank = player.Rank.Value,
			BlackoutLevel = player.GunLevels.BlackoutLevel.Value,
			MP7Level = player.GunLevels.MP7Level.Value,
			campaignLevel = player.campaignLevel.Value,
			CurrentObjective = player.CurrentObjective.Value,
		}
		local teleportTime = 0
		for i=1,#list do
			if game.Players:findFirstChild(list[i]) then
				table.insert(playersToTeleport,game.Players:findFirstChild(list[i]))
				TransitionEvent:FireClient(game.Players:findFirstChild(list[i]))
			else
				table.remove(list,i)	
			end
		end 
		
		local code = TS:ReserveServer(placeId)
		teleporting = true

		TS:TeleportToPrivateServer(placeId, code, playersToTeleport, nil, TPdata)
		repeat wait() until #list <= 0
		billboard.Frame.Status.Text = "READY"
		billboard.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
		teleporting = false
	end
end

this is the function that is supposed to teleport the player to another place, if there are players in the teleport zone. This function is kept in a while loop, so I won’t be able to add any built in functions or parameters without changing the entire thing, which I don’t have the time or patience for. The problem is, where you see the variable “Tpdata”, “player” is not being defined anywhere, and I don’t know how to define it.

Is there any simple way of getting the player, or should I have to change a lot of my scipt? If I would have to add some parameters then feel free to let me know, I can show my full script if its needed.

Is the script a Local script? if so add this variable

local Player = game.Players.LocalPlayer

The problem comes a little complex if you do the server you have some ways to get them from the Server

  • Loops
for _, Player in pairs(game.Players:GetPlayers()) do
-- the Player is here.
end
  • Player Added
game.Players.PlayerAdded:Connect(function()

end
  • Remote events (there are lots of way to do it with remote events, here is one)
local Player = nil -- add this in variables

Once the Remote events get Fired to the sever do this

RemoteEvent.OnServerEvent:Connect(function(PlayerThatFired)
PlayerThatFired = Player
end)

After that you could use the Player

1 Like

PlayerAdded with the player as the parameter (i think its called)

It’s a server script

aaaaaaaaa

PlayerAdded or remotes thennnn

Would I place it in the function?

Please read, I’ve said how you would get the Player from the server to.

Well the function would be INSIDE the PlayerAdded function

well how would I access that function outside of the playeradded?

oh mb

aaaaaaaaaaaaaaaaaaaaaaaaaa

game.Players.PlayerAdded:Connect(function(player) teleportPlayers(player) end)