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

How to get my data store to update when the money changes?

Asked by 4 years ago

Ok, I am trying to make the money that the player gets save so that when they next come on the game they keep their money. However it does not seem to be working. It saves the 100 that I have set to be default. But when the money gets updated, it doesn't update the service. I don't know if I'm saying this right, but that's what I am understanding from it.I don't know if I'm saying this right, but that's what I am understanding from it. So here is my code:

local MoneyStore = game:GetService("DataStoreService"):GetDataStore("MoneyStore")

game.Players.PlayerAdded:Connect(function(player)   
    print("Player Added!")
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    local money = Instance.new("IntValue", leaderstats)
    money.Name = "Money"
    wait(10)
    print("Getting Player's Money! They have: "..MoneyStore:GetAsync(player.UserId))
    money.Value = MoneyStore:GetAsync(player.UserId) or 100
    MoneyStore:SetAsync(player.UserId, money.Value)
    money.Changed:Connect(function()
        print("Player's Money has been changed! Amount: ".. MoneyStore:GetAsync(player.UserId))
        MoneyStore:SetAsync(player.UserId, money.Value)
    end)
end)

game.Players.PlayerRemoving:Connect(function(player)
    print("Player Left! ".."Saving Money!")
    MoneyStore:SetAsync(player.UserId, player.leaderstats.Money.Value)
    print("Amount of money saved: ".. MoneyStore:GetAsync(player.UserId))
end)

2 answers

Log in to vote
0
Answered by 4 years ago

Use SetAsync

can't explain rn

0
i am using that TurtyWurty 5 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Have you enabled API's in your game?

Configure Game > Enable Studio Access to API Services: [X]

0
i have, because i have another data store working TurtyWurty 5 — 4y

Answer this question