Hello, I came up with a bug that you can still slide when the stamina is 0 or negative, I tried creating a intValue to go over this problem but it didn’t work
Stamina System (Handles The Stamina)
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid" ,5)
local StaminaUsed = script:WaitForChild("StaminaUsed" ,5)
local Keybind = "LeftShift"
local MaxStamina = game.StarterGui.Stamina.Bar.Keybind.maxStamina.Value
local NormalWalkspeed = 16
local SprintWalkspeed = 25
anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://8107329636"
animPlay = Humanoid:LoadAnimation(anim)
local StaminaCount = MaxStamina
local SlideUsed = script.Slided
local JumpUsed = script.Jumped
local breathing = script.Parent["Heavy Breathing ( Man )"]
local runService = game:GetService("RunService")
--function regenerateStamina(delayTime,staminaType)
-- --This loop will stop if the MaxStamina was reached or the player performed any action that uses stamina
-- repeat
-- task.wait(delayTime)
-- if StaminaCount < MaxStamina then
-- StaminaCount = StaminaCount + 0.25
-- script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
-- script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
-- print(staminaType .. " Being Filled")
-- end
-- until StaminaCount == MaxStamina or JumpUsed.Value == true or SlideUsed.Value == true and StaminaUsed.Value == true
--end
local RunService = game:GetService("RunService")
local debounce = false
local player = game.Players.LocalPlayer
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAddeed:Wait()
local UIS = game:GetService("UserInputService")
local humanoid = player.Character.Humanoid
local debounce = false
local cooldown = 0.5
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=8107348885"
function regenerateStamina(delayTime)
local usingAbility = function()
return JumpUsed.Value == true or SlideUsed.Value == true or StaminaUsed.Value == true
end
if StaminaCount < MaxStamina and not usingAbility() and not debounce then
debounce = true
StaminaCount = StaminaCount + 1
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
print("Stamina Being Filled")
task.wait(delayTime)
debounce = false
end
end
RunService:BindToRenderStep("RegenerateStamina", 200, function()
regenerateStamina(0.25)
end)
UIS.InputBegan:Connect(function(key, processed)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode[Keybind] and StaminaCount > 0 then
StaminaUsed.Value = true
elseif key.KeyCode == Enum.KeyCode.Q and StaminaCount > 0 then
SlideUsed.Value = true
elseif key.KeyCode == Enum.KeyCode.Space and StaminaCount > 0 then
JumpUsed.Value = true
end
end
end)
UIS.InputEnded:Connect(function(key, processed)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode[Keybind] then
StaminaUsed.Value = false
elseif key.KeyCode == Enum.KeyCode.Q then
SlideUsed.Value = false
elseif key.KeyCode == Enum.KeyCode.Space then
JumpUsed.Value = false
end
end
end)
StaminaUsed.Changed:Connect(function()
if StaminaUsed.Value == true and Humanoid.MoveDirection.Magnitude > 0 then
Humanoid.WalkSpeed = SprintWalkspeed
animPlay:Play()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
wait()
end
repeat
wait(0.1)
if StaminaCount > 0 then
StaminaCount = StaminaCount - 1
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
end
until
StaminaCount <= 0 or StaminaUsed.Value == false
Humanoid.WalkSpeed = NormalWalkspeed
elseif StaminaUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
breathing.Playing = false
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
end
end)
SlideUsed.Changed:Connect(function()
if SlideUsed.Value == true then
local deb2 = true
if StaminaCount > 0 and deb2 == true then
deb2 = false
StaminaCount = StaminaCount - 10
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
wait(1.2)
deb2 = true
end
elseif SlideUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
end
end)
JumpUsed.Changed:Connect(function()
if JumpUsed.Value == true then
local deb3 = true
if StaminaCount > 0 and deb3 == true then
deb3 = false
StaminaCount = StaminaCount - 10
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
wait(1.2)
deb3 = true
end
elseif JumpUsed.Value == false then
Humanoid.WalkSpeed = NormalWalkspeed
animPlay:Stop()
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) -- make FOV smaller
wait()
end
end
end)
Slide Handler (Makes Sliding Work)
local player = game.Players.LocalPlayer
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAddeed:Wait()
local UIS = game:GetService("UserInputService")
local humanoid = player.Character.Humanoid
local debounce = false
local cooldown = 0.5
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid" ,5)
local StaminaUsed = script:WaitForChild("StaminaUsed" ,5)
local Keybind = "LeftShift"
local MaxStamina = game.StarterGui.Stamina.Bar.Keybind.maxStamina.Value
local NormalWalkspeed = 16
local SprintWalkspeed = 25
local StaminaCount = MaxStamina
local runService = game:GetService("RunService")
local RunService = game:GetService("RunService")
local debounce = false
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=8107348885"
UIS.InputBegan:Connect(function(input,IsTyping)
if IsTyping then
return
elseif input.KeyCode == Enum.KeyCode.Q then
if debounce == false then
debounce = true
local playAnim = humanoid:LoadAnimation(anim)
playAnim:Play()
local Character = game.Workspace:WaitForChild(player.Name)
local slide = Instance.new("BodyVelocity")
slide.MaxForce = Vector3.new(1,0,1) * 30000
slide.Velocity = Character.HumanoidRootPart.CFrame.lookVector * 100
slide.Parent = Character.HumanoidRootPart
for count = 1, 8 do
wait(.1)
slide.Velocity *= .7
end
playAnim:Stop()
slide:Destroy()
wait(cooldown)
debounce = false
end
end
end)
local UIS = game:GetService("UserInputService")
local char = script.Parent
local slideAnim = Instance.new("Animation")
slideAnim.AnimationId = "https://www.roblox.com/assets/?id=7304176908"
local keybind = Enum.KeyCode.LeftControl
local canslide = true
UIS.InputBegan:Connect(function(input,gameprocessed)
if gameprocessed then return end
if not canslide then return end
if input.KeyCode == keybind then
canslide = false
local playAnim = char.Humanoid:LoadAnimation(slideAnim)
playAnim:Play()
local slide = Instance.new("BodyVelocity")
slide.Name = "Slide"
slide.MaxForce = Vector3.new(1,0,1) * 30000
slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 100
slide.Parent = char.HumanoidRootPart
for count = 1, 8 do
wait(.1)
slide.Velocity *= .7
end
playAnim:Stop()
slide:Destroy()
canslide = true
if StaminaCount == 0 and char.HumanoidRootPart:FindFirstChild("Slide") then
local slide = char.HumanoidRootPart:FindFirstChild("Slide")
slide.Velocity = 0
end
end
end)