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 4 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.


--Datastore service local DSS = game:GetService("DataStoreService") local Money = DSS:GetDataStore("Cash") game.Players.PlayerAdded:Connect(function(plr) local pCash = Money:GetAsync(plr.UserId)or 10 local leaderstats = Instance.new("Folder",plr) leaderstats.Name = "leaderstats" local CashValue = Instance.new("NumberValue") CashValue.Name = "Cash" CashValue.Value = pCash CashValue.Parent = leaderstats CashValue.Changed:connect(function(v) Money:SetAsync(plr.UserId,v) print("MoneySaved!") end) end)
0
dekkeda it is incorrect RamenRobloxian 2 — 4y

1 answer

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

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

local DataStoreService = game:GetService("DataStoreService")
local Money = DataStoreService:GetDataStore("Cash")

function playeradded(plr)
    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = plr
    leaderstats.Name = "leaderstats"

    local Cash = Instance.new("NumberValue")
    Cash.Name = "Cash"
    Cash.Value = Money:GetAsync(plr.UserId) or 10
    Cash.Parent = leaderstats
end

function plrremoving(plr)
    Money:SetAsync(plr.UserId, plr.leaderstats.Cash.Value)
end

game.Players.PlayerAdded:Connect(playeradded)
game.Players.PlayerRemoving:Connect(plrremoving)

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

Ad

Answer this question