Health or frequently updated data (Server -> Client)

Hello guys,

I wanted to implement a simple health and stamina stuff. It sounds like data that you don’t want the player to play with, and like a lot of people on internet you may say data on the server then fire event when the value changed, is the way to go.

The truth is that I want health and stamina passive and active regen. So it would make a lot of events. I will even probably need to send the whole server stats to each player.

That’s why I’m wondering, wouldn’t the best thing be to let the “client handle it”. Of course the server will also compute the values, and it will send just one event with everything every… seconds ? Maybe a few seconds ? It won’t affect death events or stamina locked skills, because the server will be up to date.

What do you think ? Is it the good way to go ?

Thanks and have a nice day !

2 Likes

Almost always the server.
How many players would a server have that you are worried about performance issues due to the events?
You can hold a reference to all players and their stats in the server, modify what’s needed and then simply broadcast it to all clients IF it is really necessary (which I doubt).
If you were to “let the client handle it” and let the server compute the value every second it would feel super laggy and wouldn’t solve your problem at all.

1 Like

“If it’s really necessary” so each time the value changed no ?

Roblox puts a server script in each character for things like health regen. If you want to do stamina regen simply use the same script and increase/decrease the stamina when you want.

I tried, but can I safely assume that a server script won’t work for the player character ?

Why not? Serverscripts are fine inside of a player. If an exploiter deletes them, it’ll only bug out their client.

I need to check this again then ! It just didn’t work at all.

Make sure it’s in the character, not the player. For example character health regen is a script that Roblox puts in all character named “Health”

I’m stupid… yes a script server works, but it doesn’t solve the problem to get the value to the client !
Let’s forget about humanoid and health special case (which still need to use the network, but is efficient). If I have a stamina Gui I want to update on the client side, it won’t work right ?

Server ALWAYS replicates to client… Client is the the one that doesn’t replicate to server, you’ve got this all mixed up…

Objects in workspace yes, but not a table with data. Or I’m missing some documentation.
How would you get the stamina from the server then ?

Make a num value in the player, then change its value using the script.

Are you sure about it ? Just tried and the server can’t find the value. The Client can though.
I would to have a replicated storage behaviour by player though.

I guess that if you have the time to drop a project copy with a simple exemple it would be really helpful.

Are you creating the value from serverside? You can also alternatively put the value straight in starterplayer so that they spawn with it.

Just dropped the value in StarterCharacterScripts and it replicated correctly in the player character. I’m gonna try other places.

Ahhh the roblox error was misleading me, my bad !
Looks ok on my side, I’m gonna do some more check.

Okay, it works fine, thanks ^^. The client can overide the value but it won’t change for the server, and if the client just read the serve can communicate simply.
During my research I found that UnreliableRemoteEvent is best “for replicating continuously changing data”. I’m wondering if it’s a size issue, like it’s faster to use the event if there is enough big data (probably with a buffer).
Of course I told you just about Health and Stamina, but if I have more and more data. Would the event be faster and consume less ?

Nevermind the use of value object replace the need for global persistant data. And it’s probably the best solution anyway for small/medium scope.

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