Where should I store player data

I want to save player data into IntValues where can I do it so it is most accessible to local scripts and server scripts.
I tried putting it in PlayerScript & CharacterScript But I think they can’t have values.
Sorry for the lack of information but I believe this topic is pretty self explanatory,
thanks,
Felix.

1 Like

Just put the value in the player instance. (game.Players.LocalPLayer) The server can also put values there. Note that changes made on the client shouldn’t show to the server.

Alternatively, use ServerStorage.

Even better alternative without cluttering the explorer, use tables with user IDs as keys.

6 Likes

Both solutions are excellent, thanks.

Local scripts can’t touch serverstorage.

They can using module scripts right ?

You don’t want an exploiter to touch your values, which can break the game. That’s why I put them on server. On request of values, use RemoteFunction or RemoteEvent.

No, only through REs/RFs that you control.

So I rather should use RemoteEvents and RemoteFunction there is no read only property I think.

Changes made by the client to values are not replicated to the server, and this method is better since local scripts can access it. I would only suggest serverstorage for values that you don’t want the client to be able to read.

Just ran a test,
Used this on the server first

local int = Instance.new("IntValue", game.Players.azahid1)
int.Name = "int"
print(int.Value)

Used this on the client next

game.Players.LocalPlayer.int.Value = 100000
print(game.Players.LocalPlayer.int.Value)

Printed out the final value that the server saw

print(game.Players.azahid1.int.Value)

Results:
image


image
Green = Server
Blue = Client

I keep my data in ServerScriptService in DataService modules that expose endpoints for the client to query data and whatnot. :sunglasses:

No ValueObjects unless I’m looking for a visual hierarchy or I think that my game could work well with them as opposed to trying to force everything into a script format.

For me, ill put it at ServerStorage.

What I usually do is create a table and have all the data stored inside of it, that way you’re not using up extra memory with IntValues, BoolValues etc.

Example of the table:

local dataTemplate = {
	leaderstats = {
		["Cash"] = 0
	};
	
	hiddenStats = {
		["JoinTime"] = os.time()
	};
}

(I also use _G to access the data through other scripts)

Can’t I use module scripts to do this ?

Do you mean Module Scripts? If so, yes that’s what I am talking about. Either through Module Scripts or Server Scripts, it’s your choice.

Yeah, that’s what I meant, module script.