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

Using Tables for data?

Yes I have heard of this when I was previously introduced to Tables. I also heard that they can store data, strings, integers, and whatnot, But, how would you access them in Data terms? I know how to access one, easily, and also how to make one. But what would be a good example of using a Table to store Data. I mean, they can store integers, so they can store a player's money. They can store strings, maybe t a rank. But how would you use them in this sort of matter?

1 answer

✓ Accepted answer

Data Persistence is deprecated and you should use Data Store.

Anyways, there are methods for the player object which are: WaitForDataReady, SaveNumber, SaveString, SaveInstance, SaveBoolean, LoadNumber, LoadString, LoadInstance, LoadBoolean,

You want to WaitForDataReady before saving and loading when they join the game. So to save a number (let's say how much cash they have) we can use the SaveNumber method. And when they rejoin the game we can load it using the LoadNumber method.

Game.Players.PlayerAdded:connect(function(player) -- When someone joins
	player:WaitForDataReady(); -- Make sure we can save/load
	local savedMoney = player:LoadNumber("Money"); -- How much money was saved
	print(player.Name .. " had: $" .. savedMoney .. " saved up!"); -- Print how much money was saved.
	player:SaveNumber("Money", savedMoney + 10); -- Add 10 to how much money they saved (this will happen every time they join)
end);

1 comment

0

Not sure why I'm getting negative votes but okay.

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