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

Leaderboard cash system ?

Asked by 5 years ago
Edited 5 years ago

Hello guys, i need your help for my leaderboard script, the cash value increase +1 per second in roblox studio but not in roblox game, the value stay at zero :/ idea ?

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
 local leader = Instance.new("Folder",player)
 leader.Name = "leaderstats"
 local Cash = Instance.new("IntValue",leader)
 Cash.Name = "Cash"
 Cash.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, Cash.Value)
 Cash.Changed:connect(function()
  ds:SetAsync(player.UserId, Cash.Value)
 end)
end)


game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.leaderstats.Cash.Value)
end)

while wait(1) do
 game.Players.LocalPlayer.leaderstats["Cash"].Value=game.Players.LocalPlayer.leaderstats["Cash"].Value+1
end 

Click on view source for all code

0
Your script is local? Ince_FS 13 — 5y

2 answers

Log in to vote
-1
Answered by 5 years ago
local DataStore = game:GetService("DataStoreService"):GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:Connect(function(Player)
    local key = "id-"..Player.userId
    local Leaderstats = Instance.new("Folder", Player)
    Leaderstats.Name = "leaderstats"
    local Cash = Instance.new("IntValue", Leaderstats)
    Cash.Value = 0
    Cash.Name = "Cash"
    local GetCash = DataStore:GetAsync(key)
    if GetCash then
        Cash.Value = GetCash[1]
    else
        local SaveCash = {Cash.Value}
        DataStore:SetAsync(key, SaveCash)
    end
    Cash.Changed:Connect(function()
        local SAve = {Cash.Value}
        DataStore:SetAsync(key, SAve)
    end)
    while wait(1) do
        Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 1
        wait()
    end
end)

game.Players.PlayerRemoving:Connect(function(Player)
    local key = "id-"..Player.userId
    local SaveMoney = {Player.leaderstats.Cash.Value}
    DataStore:SetAsync(key, SaveMoney)
end)

0
Explain your code, don't just give a solution. Aimarekin 345 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Thank you, the code is good and working, but i have an other problem.. when i disconnect the cash continue to increase the value..

Exemple: i disconnect with 15 Cash, if i reconnect the value of Cash is 18 or 19 or 20, it's random :/

Maybe the savesystem is not perfect ? you have a solution for this ?

Sorry for my bad english

0
Try to remove the, "Cash.Changed" function. Lava_Scripter 109 — 5y

Answer this question