Ad
Log in to vote
0

How to transfer data between Places?

Asked by 14 days ago

Despite my research from the internet, nothing I do works. How do I transfer Data between Place? I copied the following script to both Places as a script: (In ServerScriptService)

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("JumpStats")

game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("Folder", Player)
    leaderstats.Name = "leaderstats"

    local Rebirths = Instance.new("IntValue", leaderstats)
    Rebirths.Name = "Rebirths"
    Rebirths.Value = 0

    local Jumps = Instance.new("IntValue", leaderstats)
    Jumps.Name = "Jumps"
    Jumps.Value = 50

    local Gems = Instance.new("IntValue", leaderstats)
    Gems.Name = "Gems"
    Gems.Value = 0

    local Data = DataStore:GetAsync(Player.UserId)
    if Data then
        Rebirths.Value = Data.Rebirths
        Jumps.Value = Data.Jumps
        Gems.Value = Data.Gems
        if Data.Jumps < 50 then
            Jumps.Value = 50
            Data.Jumps = 50
        end
    else
        warn("Data equals to false for", Player.Name)
        Jumps.Value = 50
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    DataStore:SetAsync(player.UserId, {
        ["Rebirths"] = player.leaderstats.Rebirths.Value;
        ["Jumps"] = player.leaderstats.Jumps.Value;
        ["Gems"] = player.leaderstats.Rebirths.Value;
    })
end)


The script I use to teleport from the first place to the second place is:

local TeleportService = game:GetService("TeleportService")
local Place = 9968872946
local tpGui = game.ReplicatedStorage.TeleportGui

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        TeleportService:SetTeleportGui(tpGui)
        TeleportService:Teleport(Place, player)
    end
end)

1 answer

Log in to vote
0
Answered by 14 days ago

Since I could not solve this, I decided to use teleport data and the problem was solved. Teleport Script:

script.Parent.Touched:Connect(function(hit)
    local TeleportService = game:GetService("TeleportService")
    local placeId = 9968872946

    local Players = game:GetService("Players")
    local player = Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        local teleportData = {
            Jumps = player.leaderstats.Jumps.Value,
            Rebirths = player.leaderstats.Rebirths.Value,
            Gems = player.leaderstats.Gems.Value
        }
        TeleportService:Teleport(placeId, player, teleportData)
    end
end)

Local Script for get teleport data: (In StarterPlayerScripts)

local TeleportService = game:GetService("TeleportService")
local player = game.Players.LocalPlayer
wait(5)
local teleportData = TeleportService:GetLocalPlayerTeleportData()
if teleportData then
    player.leaderstats.Jumps.Value = teleportData.Jumps
    player.leaderstats.Rebirths.Value = teleportData.Rebirths
    player.leaderstats.Gems.Value = teleportData.Gems
end
0
That's the solution, but I don't think I can mark my own message as the solution. Alperenyazar0 0 — 14d
0
Can you close the thread? fiddyfiddler 18 — 13d
Ad

Answer this question