Worried about performance with server-sided scripts

So,

I’ve made a Hunger system for my game that works with attributes on set the player.

It works with a loop that repeats every HungerUpdateTime.

Every time the loop repats, a HungerValue is decreased by one. The player dies when the HungerValue reaches 0.

Now, these attribute changes are handled through a ServerScript because I’ve read on multiple topics that exploiters are able to modify anything that runs on the client, thus, I’m afraid they might change the HungerUpdateTime to something ridiculously high, like for example, 99999 seconds. If they achieve this, the hunger wouldn’t change at all for them.

Now,

my current system works fine but I’m worried it might cause server lag since it runs on the server for ALL the players at the same time.

I want:

Some guidance on how to make server scripts more optimized since my game will run mostly on these. I only plan on using LocalScripts for stuff like the GUI, etc…

If the loop isn’t running quickly it will usually not cause any peformance issues.

A runservice loop runs every frame for example, and if you then loop through the entire game every frame and edit/reoder the descendants, it will definetely cause some peformance changes.

You can look at the script peformance tab, which displays only some of the lag of course, since you’re playing solo in studio, however it will show you if you have a very laggy script. If you aren’t already, you should keep the hunger bar UI logic on the client.

1 Like