Hey developers.
As I am sure you are aware, teleport data is only able to be fetched locally. I’m trying to make a system that, when a player is shifted from game to game using TeleportService:Teleport(), the teleport data is set to a leaderstat that is then loaded into the other game.
I looked into GlobalDatastore, but I didn’t really understand it so I went with this method.
Here are my server and local scripts; what improvements can I make onto this? I feel like it is incomplete/inefficient.
Local:
local TeleportService = game:GetService("TeleportService")
local Player = game.Players.LocalPlayer
local teleportData = TeleportService:GetLocalPlayerTeleportData()
if teleportData then
if tonumber(teleportData) then
print(teleportData)
game.ReplicatedStorage.POINTS:FireServer(TeleportService)
else
Player:Kick("Teleport data did not meet requirements.")
end
else
Player:Kick("Could not retrive teleport data.")
end
Server:
local playerData = {}
game.Players.PlayerAdded:Connect(function(player)
if not playerData[player.UserId] then
playerData[player.UserId] = {
["SENTPOINTS"] = false;
}
end
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local points = Instance.new("IntValue", leaderstats)
points.Name = "Points"
end)
game.ReplicatedStorage.POINTS.OnServerEvent:Connect(function(player, value)
if not playerData[player.UserId].SENTPOINTS then
player:WaitForChild("leaderstats"):WaitForChild("Points").Value = value
end
end)