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
try Memory Stores