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

How can I transform my leaderstats script?

Asked by 2 years ago

I have a basic leaderstats script. I want to modify it to save things that are not numbers and not in leaderstats. How can I do that?

Script:

local dataStore = game:GetService("DataStoreService"):GetDataStore("MoneyData") -- MoneyData is the name of the DataStore.Change it to reset all data.
StarterMoney = 50 -- This is the amount of money new players will have

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats" -- DO NOT CHANGE THIS NAME.PLEASE!
    leaderstats.Parent = player

    local Currency = Instance.new("IntValue")
    Currency.Name = "Money" -- Change "Money" to whatever your currency is named"
    Currency.Parent = leaderstats
    Currency.Value = dataStore:GetAsync(player.UserId) or StarterMoney

    while true do
        wait(math.random(2,3))
        Currency.Value = Currency.Value+math.random(1,4)
    end
end)
game.Players.PlayerRemoving:Connect(function(player)
    dataStore:SetAsync(player.UserId, player.leaderstats.Money.Value)
end)

PS. The script is in ServerScriptService and I want the script to be in the same script.

0
u can use variables to save things, you can use a module, or global variable to pass things from the leaderstats script, however what is it exactly what you are waning to save gymsharklife1 54 — 2y

Answer this question