so whenever a player presses w key it should fire an event and then it should take away .1 from value every time player presses w
local uis = game:GetService("UserInputService") local debounce = true local m = game.Players.LocalPlayer:GetMouse() uis.InputBegan:Connect(function(key,gpe) if Enum.KeyCode.W then if debounce == true then debounce = false print("event fired") game.ReplicatedStorage.WMouseDown:FireServer(Enum.KeyCode.W,script.Parent.stam.Stamina.Value) wait(1) debounce = true end end end)
thats localscript. This is server script
game.ReplicatedStorage.WMouseDown.OnServerEvent:Connect(function(player,key,staminavalue) staminavalue = staminavalue - 1 if staminavalue == 80 then player.Humanoid.Walkspeed = 15.8 if staminavalue == 60 then player.Humanoid.Walkspeed = 15.6 if staminavalue == 40 then player.Humanoid.Walkspeed = 15.4 if staminavalue == 20 then player.Humanoid.Walkspeed = 15 if staminavalue == 0 then player.Humanoid.Walkspeed = 14 end end end end end end)