Is it necessary to store some player statistics on the server side?

I have a running mechanic in my game and I’m not sure if it’s better to store the stamina attribute on the client side or on the server side

local contextActionService = game:GetService("ContextActionService")
local plr = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local module = require(script.ToggleRun)
plr:SetAttribute("stamina", 100) 

local function onInput(actionName, userInputState)
	if userInputState == Enum.UserInputState.Begin then
		module.toggleRun(camera, plr)
	end
end

contextActionService:BindAction("toggleRun", onInput, true, Enum.KeyCode.LeftControl)

while wait(.2) do
	local humanoid = plr.Character and plr.Character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		local walkSpeed = humanoid.WalkSpeed
		local stamina = plr:GetAttribute("stamina")

		if walkSpeed > 16 and stamina > 0 then
			plr:SetAttribute("stamina", stamina - 1)
		elseif walkSpeed <= 16 and stamina < 100 then
			plr:SetAttribute("stamina", stamina + 1)
		elseif walkSpeed >= 24 and stamina <= 0 then
			module.toggleRun(camera, plr)
		end

		print(stamina)
	end
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Whenever you’re designing things like this always keep in mind that exploiters can change anything that’s on the client, so you should always have some types of sanity checks and you should always keep values such as the true stamina value on the server, otherwise an exploiter can simply access that and change it to a huge number.

1 Like

It should be stored on the client because the client can bypass the stamina check anyways, since it’s ultimately being checked on the client anyways. That is, unless you’re planning to use stamina on other things like attacks.

1 Like