TeleportData Not Working

Hey Developers!
I am just making a wins adder for my story game.
I am teleporting players from the main game into the lobby once the game has finished.
It is supposed to give them a win.
Here is my script in the main game:

for _, Player in pairs(game.Players:GetChildren()) do
	spawn(function()
		local NewGui = game.ServerStorage.Assets.GoodEnding:Clone()
		NewGui.Parent = Player.PlayerGui
		wait(5)
		local TeleportData = {
			AddWins = true,
			PlayerName = Player.UserId
			
			
		}
		TeleportService:Teleport(4832886851, Player, TeleportData)
	end)
end

Here is my wins adder script(In the lobby)

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

I am getting no errors but nothing is happening!
Help is appreciated.

2 Likes

Seems to suggest it needs to be done within a local script, given you are using ServerStorage and then trying to set what I assume would be a value needed by the server, I assume you’re using a normal script?

Make it a local script and fire the server with a remote event to add the wins

1 Like

I’ll try that…

1 Like

I’ve made a thread in the past, this can probably help you:

Basically what this talks about is that to receive the data, you have to use a local script, hence, Get*Local*PlayerTeleportData().

1 Like

So the receiving is done in the local script?

1 Like

Yes, the receiving is done on a local script. But you can send the data using either a local or a server script.

1 Like

So I can just put a local script in StarterGui? and define the player as the local player?

2 Likes

Yes, you do put it in there. Like the thread I’ve sent you, you should make your script look similar to this:

local TeleportService = game:GetService("TeleportService")
local RunService = game:GetService("RunService")
local Data = TeleportService:GetLocalPlayerTeleportData()
if not RunService:IsStudio() then
    if TeleportData ~= nil then
        print("Data")
	else
		print("No Data") -- Prints "No Data"
	end
end
2 Likes