- What do you want to achieve? Keep it simple and clear!
I want to send a simple 5 digit code from the main game to a place within that game
- What is the issue?
I tried 5 diffrent things and not even one worked, the data its just not sending to the other place, it is saving on the main game (tested with prints) but not outputting on the other one
- What solutions have you tried so far?
I tried searching everywhere but it didn’t help
Script in the main game
local function createReservedServer(player)
if game.ReplicatedStorage.Purchases.Value >= 1 then
local serverCode = generate5DigitCode()
-- Reserve a new server and get its code
local reservedServerCode = TeleportService:ReserveServer(PLACE_ID)
-- Store the server code in the DataStore
local success, errorMessage = pcall(function()
serverCodeStore:SetAsync(serverCode, reservedServerCode)
end)
if success then
print("Server code saved successfully: " .. serverCode)
updateServerCodeEvent:FireClient(player, serverCode)
player:SetAttribute("ServerCode", serverCode)
task.wait(1)
-- Create TeleportOptions and set teleport data
local teleportOptions = Instance.new("TeleportOptions")
local teleportData = {
code = serverCode
}
teleportOptions:SetTeleportData(teleportData)
teleportOptions.ShouldReserveServer = true
-- Teleport the player to their reserved server with teleport options
TeleportService:TeleportAsync(PLACE_ID, {player}, nil, teleportOptions)
print("Teleporting")
else
warn("Failed to save server code: " .. errorMessage)
end
end
end
And the other script in the Place:
game.Players.PlayerAdded:Connect(function(player)
task.wait(1)
local teleportData = player:GetJoinData()
local TpData = teleportData.teleportData
if TpData then
print("Received server code:", TpData.code)
game.ReplicatedStorage.Stuff.UpdateCode:FireClient(player,tostring(TpData.code))
end
end)