hello, I was working on my stamina system and I wanted it to decrease stamina by 20 if you press q and decrease stamina by 10 if they jump, I tried to do this but it didn’t work, only using shift works for sprinting
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 = 100
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 )"]
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
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
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
repeat
wait(0.1)
if StaminaCount < MaxStamina then
StaminaCount = StaminaCount + 1
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
end
until
StaminaCount == MaxStamina or StaminaUsed.Value == true
end
end)
UIS.InputBegan:Connect(function(input,gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.Q and StaminaCount > 0 then
SlideUsed.Value = true
end
end
end)
UIS.InputBegan:Connect(function(input,gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.Q and StaminaCount > 0 then
JumpUsed.Value = true
end
end
end)
SlideUsed.Changed:Connect(function()
local deb2 = true
if SlideUsed.Value == true then
StaminaCount = StaminaCount - 20
end
end)
JumpUsed.Changed:Connect(function()
if JumpUsed.Value == true then
if StaminaCount > 0 then
StaminaCount = StaminaCount - 10
script.Parent.Frame.Size = UDim2.new(StaminaCount / MaxStamina, 0, 1, 0)
script.Parent.Info.Text = StaminaCount.. "/" ..MaxStamina
end
end
end)