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
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)
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