Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How Should I Save Gui Stats for Every Player?

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

✓ Accepted answer

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)

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

2 comments

0

I did indeed. I thought datastore was for leaderstats only. My bad.

0

It can save any data

This discussion is preserved as it was. New answers, comments, and votes are closed.