Hewwo, I’m Tsu Washington, a LGBT programmer Furry. So, I was working on a stamina bar System, and it actually works a bit, but it’s not perfect. It’s not in the same location, your stamina become negative or more than normal, and others.
Video Area.
Stamina Bar Bug. [ It’s not showing the image for some reason, but you can watch clicking on the link. ]
Code Area
--//Character and Humanoid\\--
local Character = script.Parent
local Humanoid = Character:WaitForChild('Humanoid')
local HRP = Character:WaitForChild('HumanoidRootPart')
--//Animations\\--
local RunAnimation = Instance.new('Animation', Character)
RunAnimation.AnimationId = 'rbxassetid://6741204780'
--//Camera\\--
local Camera = game.Workspace.CurrentCamera
--//UserInputService\\--
local UIS = game:GetService('UserInputService')
--//TweenService\\--
local TS = game:GetService('TweenService')
local TweenInfo01 = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut, 0, false, 0)
local CameraTweenIn = TS:Create(Camera, TweenInfo01, {FieldOfView = 80})
local CameraTweenOut = TS:Create(Camera, TweenInfo01, {FieldOfView = 70})
--//RunService\\--
local RS = game:GetService('RunService')
--//Players\\--
local P = game:GetService('Players')
local Player = P.LocalPlayer
--//Others\\--
Debounce = false
CanRemoveStamina = true
CanAddStamina = true
local MaxStaminaSize = UDim2.new(0.97, 0,0.755, 0)
local MinStaminaSize = UDim2.new(0, 0, 0.755, 0)
local OldRunningPlaybackSpeed = HRP:WaitForChild('Running').PlaybackSpeed
--//Scripting\\--
local Track01
Track01 = Humanoid:LoadAnimation(RunAnimation)
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift or Input.KeyCode == Enum.KeyCode.RightShift then
if Player.PlayerGui.StaminaGui.Background.Bar.Size ~= MinStaminaSize then
HRP:WaitForChild('Running').PlaybackSpeed = OldRunningPlaybackSpeed + 0.2
Humanoid.WalkSpeed = 22
CameraTweenOut:Pause()
CameraTweenIn:Play()
end
end
end)
UIS.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift or Input.KeyCode == Enum.KeyCode.RightShift then
if Player.PlayerGui.StaminaGui.Background.Bar.Size ~= MinStaminaSize then
HRP:WaitForChild('Running').PlaybackSpeed = OldRunningPlaybackSpeed
Humanoid.WalkSpeed = 16
CameraTweenIn:Pause()
CameraTweenOut:Play()
end
end
end)
RS.RenderStepped:Connect(function()
if Humanoid.WalkSpeed == 22 then
if Humanoid.MoveDirection.Magnitude > 0 then
if Player.PlayerGui.StaminaGui.Background.Bar.Size ~= MinStaminaSize then
if CanRemoveStamina == true then
CanRemoveStamina = false
Player.PlayerGui.StaminaGui.Background.Bar.Size -= UDim2.new(0.005, 0, 0, 0)
wait(0.07)
CanRemoveStamina = true
end
end
if Debounce == false then
Debounce = true
Track01:Play()
Track01.Stopped:Wait()
Debounce = false
end
else
if Track01 then
Track01:Stop()
end
if Player.PlayerGui.StaminaGui.Background.Bar.Size ~= MaxStaminaSize then
if CanAddStamina == true then
CanAddStamina = false
wait(0.2)
Player.PlayerGui.StaminaGui.Background.Bar.Size += UDim2.new(0.005, 0, 0, 0)
wait(0.07)
CanAddStamina = true
end
end
end
else
if Track01 then
Track01:Stop()
end
if Player.PlayerGui.StaminaGui.Background.Bar.Size ~= MaxStaminaSize then
if CanAddStamina == true then
CanAddStamina = false
wait(0.2)
Player.PlayerGui.StaminaGui.Background.Bar.Size += UDim2.new(0.005, 0, 0, 0)
wait(0.07)
CanAddStamina = true
end
end
end
end)
- Thanks for reading, Tsu Washington.