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

Datastores Across Universe?

Asked by 9 years ago

I've been working on my project, and it uses DataStores across a universe.

Here is script one

local datastore = game:GetService("DataStoreService"):GetDataStore("Vestige")

game.Players.PlayerRemoving:connect(function(leavingplayer)
    wait(2)
    local stats = leavingplayer:FindFirstChild("Statistics"):GetChildren()
    for x = 1,#stats do
        print(stats[x].Name)
    end
end)

game.Players.PlayerAdded:connect(function(player)
    wait(2)
    local newstats = player:FindFirstChild("Statistics"):GetChildren()
    for x = 1, #newstats do
        newstats[x].Value = datastore:GetAsync(newstats[x].Name)
    end
end)

Here is the script in the other place in the universe

local datastore = game:GetService("DataStoreService"):GetDataStore("Vestige")

script.Parent.MouseClick:connect(function(plr) 
    if plr.PlayerGui:findFirstChild("ScreenGui") then
        print("already clicked")
    else
        local cl = script.Parent.ScreenGui:Clone()
        cl.Parent = plr.PlayerGui
        game.Players.PlayerRemoving:connect(function(leavingplayer)
            leavingplayer.Statistics.Coins = leavingplayer.Statistics.Coins + 10
            wait(2)
            local stats = leavingplayer:FindFirstChild("Statistics"):GetChildren()
            for x = 1,#stats do
                print(stats[x].Name)
            end
        end)
    end
end)

The GUI part of the second script works, but it doesn't add any more coins. Could anyone help?

0
What is the problem exactly? MisaMiner 50 — 9y
0
It doesn't save the coins. You're meant to get coins in one place, and they save into the statistics folder on the next place. Citrino 0 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Try removing the wait(2)s. Its possible that due to the player leaving, the player leaves before the data can be saved.

Ad

Answer this question