TeleportService: TeleportData

  1. What do you want to achieve? I want to make it so that it gives a win to all players in a team but the match is in 1 place and the lobby is in 1 place too. (How to add multiple places inside a place? - #3 by Polyheximal)

  2. What is the issue? The issue is that it’s not saving the player’s win when they rejoin the lobby.

  3. What solutions have you tried so far? I have tried looking around the DevForum but no luck.

LocalScript = StarterPlayer > StarterPlayerScripts

local teleportService = game:GetService("TeleportService")

local teleportData = teleportService:GetLocalPlayerTeleportData()

if teleportData then

local Player = game.Players:GetPlayerByUserId(teleportData.PlayerName)

Player:WaitForChild('leaderstats'):WaitForChild('Wins').Value = Player.leaderstats.Wins.Value + 1

end

Script = ServerScriptService

local teleportService = game:GetService("TeleportService")


	local TeleportData = {
		AddWins = true,
		PlayerName = Player.UserId		
	}
	
	teleportService:Teleport(9368394776, Player, TeleportData)
Player:WaitForChild('leaderstats'):WaitForChild('Wins').Value = Player.leaderstats.Wins.Value + 1

This is on a LocalScript, when it needs to be on a ServerScript.

Assuming the ServerScript you provided teleports instantly after the win, and detecs when the win happens, here’s an edited version of the ServerScript.

local teleportService = game:GetService("TeleportService")

local TeleportData = {
	AddWins = true,
	PlayerName = Player.UserId		
}

Player:WaitForChild('leaderstats'):WaitForChild('Wins').Value += 1
teleportService:Teleport(9368394776, Player, TeleportData)
1 Like

The issue with that is that the Wins stat is in the lobby not in the match…

Did you try my fix yet or no?

Your fix did not work because the leaderstat is in the lobby not in the match.

Are the scripts in the same place? Or different places?

Different places --------------

This is in the lobby ---------------

This one is in my match place -------

Why are you trying to get a player by UserId with a PlayerName?

Oh that’s a good point, I don’t remember why

Hey, im just here to point you a issue with the current script your trying to make. The teleport data is not sent on the server side but on the client side. This means that the client has direct access to the information in question. Exploiters can therefore modify this data during their teleportation or even initiate a teleportation with this data and exploit this to retrieve points in an unplanned way. The easiest way to prevent this is to use DataStoreService on the game server before you teleport the player to the lobby.

See more informations about GetLocalPlayerTeleportData

When the data concerns important game stats, you should never trust the client, and always be careful to check on the server side that all the client information you recive from remote event or functions has not been modified to exploit a “vulnerability” in your code

I have decided to use an External Database, anyways thanks for your guys’ help.