Question About Player Data Paradigms

I am relatively new to scripting on Roblox and I’ve taken note of two methodologies for storing player data. Those being that you can either store the data inside of the player using IntValues or you can store it abstractly in an array.

IntValues are easier to use because you can access them from all scripts without much hassle, but my gripe with them is that exploiters will be able to view a lot of player data which may give them the upper hand.

local function OnPlayerAdded(player)
	local folder = Instance.new("Folder")
	local money = Instance.new("IntValue")
	folder.Name = "leaderstats"
	money.Name = "Gold"
	folder.Parent = player
	money.Parent = folder
end

While on the other hand, tables are more secure but it’s more difficult to access that data from multiple different scripts.

local plrs = {}
local playertemplate = {["level"] = 1, ["gold"] = 50}

local function OnPlayerAdded(player)
	plrs[player.UserId] = playertemplate
end

Are there any other common data structures for player data that I’m missing? Which way is more optimal?

2 Likes

The difference is that the first example (IntValues) would have the leaderstats shown in the leaderboard whereas the second one (tables) wouldn’t

1 Like

Yes I know that. I will repeat my questions.

  1. Are there any other common data structures for player data that I’m missing?
  2. Which method is more optimal?
  1. Storing data in value instances and tables are the most common ways of storing player data that I know of personally.
  2. Storing data in instances is not optimal because every new player joining will create new instances that will eventually lag your game, especially if you have a lot of data to store. The better method is storing data in tables. To fix the data access issue, you could store all the player data in a module script, and all the server scripts will be able to access the player data table. For clients, you could set up a remote function where a player can request their data from the server.

Mb my English is not englishing rn

2 Likes

Yeah that reminds me that the main reason I was even considering using IntValues was because of how easy it use with the server-client boundary in mind.

Can you think of any circumstances in which using instances to store information would be preferable over storing data in a table?

If your data is very basic, then I guess it’s fine. Examples of this can be cash, gold, playtime, and other things. If it starts to get complex, like a player’s inventory, then you should opt-out of using instances to save data and use tables.

Oh yeah I guess another way I’ve seen people store data is through attributes (Do not recommend but it works)

1 Like

Yeah I’ve seen attributes utilized a bit for things like combat systems. I’m assuming you can do the same thing with tables so they’re pretty much in the same boat as instance values

you can create a folder named “leaderstats” and add your values to it and when a player joins clone it and parent it to him
example

local leaderstats = ServerStorage.Leaderstats

function onPlayerAdded(plr)
      local leaderstats = leaderstats:Clone()
      leaderstats.Parent = plr
end

every new player joining will create new instances that will eventually lag your game

I disagree with this. The amount of memory impact is negligible even with 100 players.

my gripe with them is that exploiters will be able to view a lot of player data which may give them the upper hand

This is true, reading data from instances is way easier than trying to extract variables from scripts but unless you’re doing some asymmetric stealth game the data is useless 99% of the time.

Personally the choice between storing data in roblox instances or lua is similar storing data in classes or just as a table. I think one is more concrete and easier to visualize, and you may have a more convenient time debugging while playtesting using the studio explorer, but the other is far more versatile to manipulate programmatically.

2 Likes

Yeah, but this post is about the difference between data structures using instance values (leaderstats method) to store player data vs storing player data via tables in a script

1 Like

Yeah, so you’re basically saying it’s really just preference

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.