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

How to send data when teleporting a player between games?

I'm making a level selection system and im trying to send the level number (single integer) to the other game through teleporting. I used the Roblox Dev website [https://create.roblox.com/docs/mechanics/teleporting-between-places]

but after following the instructions I get hit with an error code saying the data im sending through doesn't exist/is nil (attempt to index nil error)

Could someone help me find out what im doing wrong or if theres anything I need to add/change? Thank you very much.

Here is the code:

Server Script that sends info after pressing button

local teleportservice = game:GetService("TeleportService")
local teleportdata = {
	
	LevelNumber = 1
}

local teleportoptions = Instance.new("TeleportOptions")
teleportoptions:SetTeleportData(teleportdata)


local player = game:GetService("Players").PlayerAdded:Wait()
local placeid = 11338334502
local teleportgui = game.ReplicatedStorage.TeleportGui
teleportservice:SetTeleportGui(teleportgui)

script.Parent.MouseButton1Click:Connect(function()
	teleportservice:TeleportAsync(placeid, {player}, teleportoptions)
end)

Server Script that recives info

local Players = game:GetService("Players")

local function onPlayerAdded()
	local player = game:GetService("Players").PlayerAdded:Wait()
	local joinData = player:GetJoinData()
	local teleportdata = joinData.teleportdata
	local levelNumber = teleportdata.LevelNumber

	print(player.Name .. "joined with level " .. levelNumber)
	
end

Players.PlayerAdded:Connect(onPlayerAdded)

1 comment

0

try Memory Stores

2 answers

✓ Accepted answer

There a few issues with what you are trying to accomplish, the main one being that the Teleport Data you are sending is exposed to the client, meaning the client can tamper with the data while teleporting. If this does not concern you, let's move on.

According to the Roblox documentation (found here), you will need to have everything in a LocalScript. When the player is teleported, the TeleportService.LocalPlayerArrivedFromTeleport event will be fired, and this is where you can get the player's teleport data. Follow the documentation example for more information.

1 comment

0

Thanks for your help! Documentation helped lots, seems the other website is outdated or wrong? Not sure. Anyways thank you!

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