guys i have a jump stamina script whenever you jump it reduces the stamina and if you have no stamina you cant jump. but when in terrain water the jump stamina depletes instantly cuz it fires so fast. I dont want to add a time jump cooldown but a stamina based cooldown because i need players to be able to get onto rafts easily
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Gui = script.Parent
local Frame = Gui:WaitForChild("Frame")
local Bar = Frame:WaitForChild("Bar")
Gui.Enabled = true
local MaxStamina = 140
local Stamina = 140
local Swimming = false
local Humanoid = Character.Humanoid
local function RefilStamina()
local IsJumping = false
task.spawn(function()
IsJumping = Humanoid.Jumping:Wait()
end)
task.wait(3)
while Stamina < MaxStamina and not IsJumping do
Stamina = Stamina + 5
Bar.Size = UDim2.new(1,0,Stamina/MaxStamina,0)
if Stamina >= 20 then
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
task.wait(.2)
if Stamina == MaxStamina then
Bar.Visible = false
end
end
end
end
Humanoid.Jumping:Connect(function(Active)
if Active and Humanoid:GetState() ~= Enum.HumanoidStateType.Swimming and Humanoid:GetState() ~= Enum.HumanoidStateType.Seated then
Bar.Visible = true
Bar.Size = UDim2.new(1,0,Stamina/MaxStamina,0)
if Stamina < 20 then
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
else
RefilStamina()
end
end)