i was tryna make a basic stamina system unfortunatly whenever the running attribute is on it reduces stamina like intended however when the running attribute is off it still reduces the stamina, how would I fix this?
local player = game:GetService("Players").LocalPlayer
local stamina = player.playerstats.stamina
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local staminadrain = false
local chr = player.Character
chr:GetAttributeChangedSignal("Running"):Connect(function()
local Running = chr:GetAttribute("Running")
if chr:GetAttribute("Running") == true then
while Running == true do
stamina.Value -= 1
task.wait(0.1)
end
end
if chr:GetAttribute("Running") == false then
task.wait(2)
RunService.Heartbeat:Connect(function()
if chr:GetAttribute("Running") == false then
stamina.Value += 0.1
end
end)
end
end)
stamina.Changed:connect(function()
if stamina.Value > 100 then
stamina.Value = 100
end
if stamina.Value < 0 then
stamina.Value = 0
if stamina.Value == 0 then
chr:SetAttribute("CanRun", false)
if stamina.Value == 20 then
chr:SetAttribute("CanRun", true)
end
end
end
end)