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.