Hello, i am a "mediocre" scripter and i would like to recieve some help.
I want to know how to script Data Store saving (Cash Saving) without a "Leaderboard".
The cash counter is contained in a gui, Cash Value creates in LocalPlayer (not character).
Hello, i am a "mediocre" scripter and i would like to recieve some help.
I want to know how to script Data Store saving (Cash Saving) without a "Leaderboard".
The cash counter is contained in a gui, Cash Value creates in LocalPlayer (not character).
You don't need to use leaderstats to be able to save the stats in a datastore. Just make a table in a serverscript, and store each player's stats there, and change them as needed.
Example:
local Stats = {}
game:GetService("Players").PlayerAdded:Connect(function(plr)
Stats[plr] = DataStore:GetAsync("Data_" .. plr.UserId)
print(Stats[plr].Coins)
end)
game:GetService("Players").PlayerRemoving:Connect(function(plr)
DataStore:SetAsync("Data_" .. plr.UserId, Stats[plr])
Stats[plr] = nil
end)
local function AddCoins(plr, amount)
local plrStats = Stats[plr]
plrStats.Coins = plrStats.Coins + amount
end)
--when player gains a coin
AddCoins(plr, 1)
This discussion is preserved as it was. New answers, comments, and votes are closed.