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

How can I make this leadeboard saves your money?

Asked by
Tripyfy 28
5 years ago

I'm making a game and I need the money to be saved how could I do it?

game.Players.PlayerAdded:Connect(function(player)
    local ls = Instance.new("Folder",player)
    ls.Name = "leaderstats"

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

    local cc = Instance.new("IntValue",player)
    cc.Name = "CashCollected"

    local robbing = Instance.new("BoolValue",player)
    robbing.Name = "Robbing"
    robbing.Value = false

    player.CharacterAdded:Connect(function(char)
        player.Robbing.Value = false
        player.CashCollected.Value = 0
    end)

end)

3 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Hi Tripyfy,

You just need to use DataStoreService to store it. I won't teach you how to do it, but there are many tutorials on youtube and wiki you can check out. Here is the link to a youtube tutorial that helped me out a lot.

Hope i helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

Ad
Log in to vote
0
Answered by
valchip 789 Moderation Voter
5 years ago

You can use DataStore or Save Instance. http://wiki.roblox.com/index.php?title=Data_store http://wiki.roblox.com/index.php?title=API:Class/Player/SaveInstance

Log in to vote
0
Answered by 5 years ago

Try this script:

local ds = game:GetService("DataStoreService")
game.Players.PlayerAdded:Connect(function(player)
    local data = ds:GetAsync("player_" .. player.UserId) or 0
    local ls = Instance.new("Folder",player)
    ls.Name = "leaderstats"
    local money = Instance.new("IntValue",ls)
    money.Name = "Money"
    money.Value = data
    local cc = Instance.new("IntValue",player)
    cc.Name = "CashCollected"
    local robbing = Instance.new("BoolValue",player)
    robbing.Name = "Robbing"
    robbing.Value = false
    player.CharacterAdded:Connect(function(char)
        player.Robbing.Value = false
        player.CashCollected.Value = 0
    end)
end)
game.Players.PlayerRemoving:Connect(function(player)
    ds:SetAsync("player_" .. player.UserId, player:WaitForChild("leaderstats").Money.Value)
end)
0
it doesnt work for me ;8 Tripyfy 28 — 5y
0
It does NOT work in studio, sorry. User#22219 20 — 5y
0
Unless if you let studio to access API Services. User#22219 20 — 5y

Answer this question