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

I need help on a save system to save the players money?

Asked by 3 years ago

So my problem is that I need to save the amount of money that a player has so that when the player joins again the player's money will be saved. This is my code, any help would be appreciated.

local function addBoard(player)
    local board = Instance.new("Folder", player)
    board.Name = "leaderstats"

    local money = Instance.new("IntValue", board)
    money.Name = "Money"
end

game.Players.PlayerAdded:Connect(addBoard)
0
You can do that with datastores. I recommend you to watch some videos on youtube about Datastores. Ferrarimami 120 — 3y
0
umm thats what i wanna know minishyft -25 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
local DataStore = game:getService("DataStoreService")

local MoneyStore = DataStore:GetDataStore("MoneySaveSystem")

game.Players.PlayerAdded:connect(function(Player)
    local leaderstats = Instance.new("Folder", Player)
    leaderstats.Name = "leaderstats"

    local Money= Instance.new("IntValue", leaderstats)
    Money.Name = "Money"
    Money.Value = MoneyStore:GetAsync(Player.UserId) or 0
    MoneyStore:SetAsync(Player.UserId, Money.Value)

    Money.Changed:connect(function()
        MoneyStore:SetAsync(Player.UserId, Money.Value)
    end)

game.Players.PlayerRemoving:connect(function(Player)
        MoneyStore:SetAsync(Player.UserId, Player.leaderstats.Money.Value)
    end)
end)

Hope its can help you

Ad

Answer this question