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

What's wrong with this DataStore script?

Asked by
Hasburo 150
8 years ago
local ds = game:GetService("DataStoreService"):GetGlobalDataStore("Valor")

game.Players.PlayerAdded:connect(function(player)

    local stats = Instance.new("IntValue", player)
    stats.Name = "leaderstats"

    local valor = Instance.new("IntValue", stats)
    valor.Name = "Valor"

    if ds:GetAsync(player.userId) ~= nil then
        valor.Value = ds:GetAsync(player.userId)
    end
    while true do
        ds:SetAsync(player.userId,valor.Value)
    end
end)

Lookie here,

I've been reviewing the wiki, watching YouTube videos, and checking out other developers' uncopylocked games for hours now.

So help would be GREATLY appreciated.

So the purpose of this script is to save the IntValue "Valor", which it does. However, the catch is I am trying to save it across several games.

What I'm looking for here is an explanation as of to how the entire universe thing works, and as of to how to make this work across several games.

0
Tip: Make it while wait() do. If it doesn't wait, it'll crash your game. Shawnyg 4330 — 8y

1 answer

Log in to vote
2
Answered by 8 years ago

Fix: That while loop isn't very good, it'll just lag the player. Instead, make it a .Changed event:

valor.Changed:connect(function()
    ds:SetAsync(player.UserId,valor.Value)
end)

To answer your question:

Wiki article: http://wiki.roblox.com/index.php?title=Game

You shouldn't need to do anything special, DataStores carry across universes. Just make sure to put that script into every place in the universe.

Hopefully this helped, if you need anything, tell me in the comments!

~TDP

0
Is it possible to do it without a universe? The games I want to connect it across are several games and it'd be a pain I really don't want people to have go to the universe just for points to save. Hasburo 150 — 8y
0
Yes, it only works on the universe. You could try using something like trello, but I wouldn't recommend it since you're making files for each player. TheDeadlyPanther 2460 — 8y
Ad

Answer this question