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

DataStore + leaderstats Not working?

Asked by 7 years ago
Edited 7 years ago

So, I'm trying to make a DataStore and a Leaderstats script all in one, the script is a normal script in ServerScriptService

game.Players.PlayerAdded:connect(function(player)
    local key = "user_"..player.UserId  
    local folder = Instance.new("Folder")
    folder.Parent = player
    folder.Name = "stores"
    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = player
    leaderstats.Name = "leaderstats"    
    local money = Instance.new("IntValue", player)
    money.Name = "Money"
    local lemon = Instance.new("IntValue")
    lemon.Parent = player.stores
    local dss = game:GetService("DataStoreService")
    local moneyds = dss:GetDataStore("money")



    moneyds:UpdateAsync(key, function(oldValue)     
        if oldValue == 0 then
            local newValue = 0
            newValue = newValue + 60
            return newValue
        end 
    end)
    money.Value = moneyds:GetAsync(key) 
end)

Sorry if this is completely wrong, it's been a while since I've done DataStores

0
Btw, make sure Studio API Access is Enabled. ;) Scarious 243 — 7y

1 answer

Log in to vote
0
Answered by
Scarious 243 Moderation Voter
7 years ago

I will fix that datastore part for yah!

game.Players.PlayerAdded:connect(function(player)
    local key = "user_"..player.UserId  
    local folder = Instance.new("Folder")
    folder.Parent = player
    folder.Name = "stores"
    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = player
    leaderstats.Name = "leaderstats"    
    local money = Instance.new("IntValue", player)
    money.Name = "Money"
    local lemon = Instance.new("IntValue")
    lemon.Parent = player.stores
    local dss = game:GetService("DataStoreService")
    local moneyds = dss:GetDataStore("money")

    local moneyval = moneyds:GetAsync(key) or 60
    money.Value = moneyval
end)

0
I re-wrote the whole script and it works, but thanks for the help anyway! theawesome624 100 — 7y
Ad

Answer this question