Need help for stamina script

First off, I’ve already attempted several approaches in order to create a stamina system.

Basically the system I have in place is that each use who spawns into the game has a stamina meter on the right side of their screen and depending how much stamina is available, the bar lowers or extends by the percentage that the player can use.

My problem is not that I don’t understand how to make a stamina system, but rather that I am stumped to the server security side of the problem. If I update the value on the server, then the latency in regards to getting a return value through remote event is very noticable; same issue is present with stamina regeneration.

This is really confusing, my head is about to explode…


Why do you need to communicate with the client? Stamina is something that the sever can handle alone. Taking out the need for the Remote Event removes the latency.

Each client needs to have their own GUI so that they can see the percentage of stamina that is available to them, as well as the fact that the client needs to control input for actions such as sprinting, and other abilities.

It’s not the most effective method but I created Value objects in ReplicatedStorage to test this. The client reads all necessary information from the values (that are updated by the server) and sends requests if they start doing any actions. So for example if they player presses shift, the client sends a request to the server. Then the server checks to see if the player’s stamina value has enough to sprint, and decreases it if the player is sprinting. Any changes to that value are seen by the client as the client can read the values stored in ReplicatedStorage.

As far as I can tell, there is no latency that can be noticed in game.

Were you testing this in game rather than studio? This was pretty much my original approach except I used remote events for the process of telling the client the new stamina value which I’ve been told is faster.

When testing in studio with the approach I described, everything ran well but in game, things were slow to respond.

I’m still seeking help and I haven’t been able to solve the problem yet.

Just set the value of the stamina and then use the changed event to check for stamina changes on the client. It seems unnecessary to tell the client what the value of the stamina is each time it is changed.

Not sure why i’am answering this, since someone will probably flag this too.

To be honest, i think after 2 Months: image, the issue should be resolved, meaning your comment, was potentially, “useless”.

I never actually got a solution to this problem, hence why I didn’t mark any solutions, so I believe the topic is still relevant. My main problem is that no one has accounted for server to client lag.

This still doesn’t account for server to client boundary lag and I can’t just do the entire stamina script on the client otherwise hackers could just change the percentage fullness of the stamina bar. What I’m looking for is a way to somehow hide the delay on the client or use a different method with similar results.

1 Like

I meant that you could change the stamina on the server and then check for changes on the client.

As I stated before, there’s still going to be a delay when the client gets the message that the server changed the stamina.

sorry for necroposting or whatever but theres not really much you can do at that point other than look for ways to make your game run smoother since as far as i know, what @DalekAndrew99 is saying is the most efficient way of doing it