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

How do I get my currency that saves to work?

Asked by 5 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

Here is the script I used to script my currency that saves.

01--Datastore service
02local DSS = game:GetService("DataStoreService")
03local Money = DSS:GetDataStore("Cash")
04 
05 
06game.Players.PlayerAdded:Connect(function(plr)
07 local pCash = Money:GetAsync(plr.UserId)or 10
08 local leaderstats = Instance.new("Folder",plr)
09 leaderstats.Name = "leaderstats"
10 local CashValue = Instance.new("NumberValue")
11 CashValue.Name = "Cash"
12 CashValue.Value = pCash
13 CashValue.Parent = leaderstats
14 CashValue.Changed:connect(function(v)
15  Money:SetAsync(plr.UserId,v)
16  print("MoneySaved!")
17 end)
18  end)
0
dekkeda it is incorrect RamenRobloxian 2 — 5y

1 answer

Log in to vote
0
Answered by
dekkeda 30
5 years ago

your code is very unclear i have made a better version for you.

01local DataStoreService = game:GetService("DataStoreService")
02local Money = DataStoreService:GetDataStore("Cash")
03 
04function playeradded(plr)
05    local leaderstats = Instance.new("Folder")
06    leaderstats.Parent = plr
07    leaderstats.Name = "leaderstats"
08 
09    local Cash = Instance.new("NumberValue")
10    Cash.Name = "Cash"
11    Cash.Value = Money:GetAsync(plr.UserId) or 10
12    Cash.Parent = leaderstats
13end
14 
15function plrremoving(plr)
16    Money:SetAsync(plr.UserId, plr.leaderstats.Cash.Value)
17end
18 
19game.Players.PlayerAdded:Connect(playeradded)
20game.Players.PlayerRemoving:Connect(plrremoving)

If this still don't work check if you have Api acces via studio enabled.

Ad

Answer this question