I made a sprint system with stamina and i’m trying to implement a stamina bar but it doesn’t work. It doesn’t output any errors.
The local script:
local frame = script.Parent
local bar = frame:WaitForChild("Bar")
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local stamina = char:WaitForChild("Stamina")
local rs = game:GetService("RunService")
stamina.Changed:Connect(function()
bar.Size = UDim2.new(stamina.Value /100, 0, 1, 0)
end)
local frame = script.Parent
local bar = frame:WaitForChild("Bar")
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local stamina = char:WaitForChild("Stamina")
local rs = game:GetService("RunService")
stamina.Changed:Connect(function()
bar.Size = UDim2.new((stamina.Value /100)/100, 0, 1, 0)
end)
i havent tested so tell me what happens and i can tweak the numbers
maybe my brain isnt working right now so dont scream at me if it doesnt work corerectly
Bruh, i made it so the bar size will change everytime the stamina decreases or increases instead of changing it everytime you hold shift and it worked.
uis.InputBegan:Connect(function(key, processed)
if key.KeyCode == Enum.KeyCode.LeftShift then
if bool.Value == true and running == false and hum.MoveDirection.magnitude > 0 and stamina > 0 then
running = true
sprint:Play()
fov:Play()
while running do
task.wait(0.075)
print(stamina)
bar.Size = UDim2.fromScale(stamina / maxStamina, 1)
stamina -= 1
if stamina == 0 then
tired:Play()
normal:Play()
running = false
end
end
end
end
end)
uis.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
if stamina > 0 then
running = false
walk:Play()
normal:Play()
else
running = false
tired:Play()
normal:Play()
end
task.wait(3)
while not running and stamina ~= 100 do
wait(0.01)
bar.Size = UDim2.fromScale(stamina / maxStamina, 1)
stamina += 1
end
end
end)