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

Saving an IntValue help?

Asked by 10 years ago

I am trying to make a script where it saves the number as you can see on the first line. I'm pretty sure this is the false way to do it but this is all the wiki gave me. I hope this is correct. Any help appreciated. This is a local script in a screen gui. The error is: 'DateStoreService' is not a valid Service name

local DataStore = game:GetService("DateStoreService"):GetDataStore(script.Parent.Number)

game.Players.PlayerAdded:connect(function(player)
    local key = "user_".. player.userId
    DataStore:UpdateAsync(key, function(oldValue)
        local newValue = oldValue or 0
        newValue = newValue + 10
        return newValue
    end)
end)

game.Players.PlayerRemoving:connect(function(player)
    local key = "user_".. player.userId
    DataStore:UpdateAsync(key, function(oldValue)
        local newValue = oldValue
        return newValue
    end)
end)

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

DataStores don't work from LocalScripts. For that matter, I don't think PlayerRemoving or PlayerAdded work in a LocalScript either.


Usually when you're using PlayerAdded or PlayerRemoving, it's a good hint you shouldn't be using a LocalScript, anyway.

Ad

Answer this question