Should this be server sided or client sided?

Hello im making a stamina script where the stamina refills to 100 ANYTIME it isn’t already at 100.
Im doing this with a while loop (Does anyone have a better way of doing this without a while loop?)

Should I do this inside a server script or a local script?

This should be serversided, as it would allow for people to easily exploit themselves inf stamina regen or whatever. Use RunService with the DeltaTime parameter to correctly regenerate the amount of stamina that should be given per frame.

So do I start the heartbeat thing in the code where the stamina value is created each time they spawn in?

for example

local staminavalue = 100

spawn(function()
 Heartbeat thing(Deltatime thing)
  if stamina ~= 100 then
  stamina += 1
  end
 end)
end)

No need for the spawn, something more like


local MAX_STAMINA = 100;
local STAMINA_REGEN_PER_SECOND = 2;

RunService.Heartbeat:Connect(function(DeltaTime)
   local staminaToRegen = STAMINA_REGEN_PER_SECOND * DeltaTime
   playersStamina = math.clamp(playersStamina + staminaToRegen, 0, MAX_STAMINA)
end)
1 Like

I would not make this server-sided, this is bad UX for the user…

EDIT: Instead of making this server-sided, I would keep both a client value and a server value.
I would “always” trust the client with its stamina value and on the server just calculate whether or not the amount of time they have been running is possible with their current stamina.

This way, you validate the sprinting whilst not sacrificing UX for the sake of “security”. It is always better to prefer UX and offer them a not “laggy” input when sprinting. (in case you were going to handle toggle sprinting on the server instead of the client of course).

You could make a sanity check on server by checking when the player started regenerating and now and checking if that amount of stamina is possible in that time frame.

But, a player could always just change their walkspeed on client unless you have an anticheat to prevent it.

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