Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to send data when teleporting a player between games?

Asked by 1 year ago

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)

0
try Memory Stores Puppynniko 1059 — 1y

2 answers

Log in to vote
1
Answered by
0x5y 105
1 year ago

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.

0
Thanks for your help! Documentation helped lots, seems the other website is outdated or wrong? Not sure. Anyways thank you! TabooAntonioiscool 42 — 1y
Ad
Log in to vote
1
Answered by 1 year ago

This could help I found a tutorial Hope this helps!!

Answer this question