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

How Should I Save Gui Stats for Every Player?

Asked by 7 years ago
Edited 7 years ago

So I'm trying to think of a way to save stats of players. They are not leaderstats but instead stats saved in a gui as IntValue's. I don't even know how to start with something like this. Can someone help? Thanks in advance. You don't have to example with a script. Just ideas are fine.

3 answers

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

Yes you can use a DataStore

http://wiki.roblox.com/index.php?title=PlayerDataStore_module

Here is a quick example:

--Server Script (DataStore must always be in a Server Script)

local datastore = game:GetService("DataStoreService"):GetDataStore("Values")
game.Players.PlayerAdded:connect(function(plr)
    local key = "user_" .. plr.UserId --Set a unique key that contains saved values for each player

    local leaderstats = Instance.new("Model", plr) --Creates a leaderboard
    leaderstats.Name = "leaderstats"

    local Cash = Instance.new("IntValue", leaderstats) --Inserts a value inside of leaderstats
    Cash.Name = "Cash" --How the value will show up in the leaderboard
    Cash.Value = datastore:GetAsync(key) or 0 --Gets "Cash"s value from the DataStore, if not found for the player, it will automatically be set to 0

    Cash.Changed:connect(function() --Checks if Cash's value was changed
        datastore:SetAsync(key, Cash.Value) --Saves Cash's value to the DataStore using the unique "key"
    end)
end)
Ad
Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
7 years ago

Datastore... Did you even look at the wiki.... or look it up....

0
I did indeed. I thought datastore was for leaderstats only. My bad. animelover6446 41 — 7y
0
It can save any data H4X0MSYT 536 — 7y
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You can use Datastore.

http://wiki.roblox.com/index.php?title=PlayerDataStore_module

I would suggest looking at this module, as it is meant to be easy to use and will help you save player stats!

Also, from now on, you should try and give some code as this is scripting helpers :)

Answer this question