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

How to make Data Store without using leaderboard?

Asked by 5 years ago
Edited 5 years ago

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

GUI SCREENSHOT

1 answer

Log in to vote
2
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

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)

Ad

Answer this question