ive tried for hours today to implement a debounce but every time i do, it allows the player to jump even if stamina hits 0. any help??
local bar = script.Parent
local stamina = 100
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local isJumping = false
local uis = game:GetService("UserInputService")
humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
if stamina == 0 then
return
end
isJumping = true
wait(1)
if isJumping then
humanoid.JumpPower = 50
wait()
end
end)
while wait() do
if stamina == 0 and isJumping then
isJumping = false
humanoid.JumpPower = 0
wait(5)
humanoid.JumpPower = 50
end
if isJumping then
humanoid.JumpPower = 50
stamina -= 5
isJumping = false
wait()
else
stamina += 0.75
wait()
end
stamina = math.clamp(stamina, 0, 100)
bar:TweenSize(UDim2.new((1/100) * stamina, 0, 1 ,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.1)
end
For the record, it doesn’t matter whether you use JumpRequest, KeyCode.SpaceBar, or GetPropertyChangedSignal, your issue lies within the function itself.
honestly there are a number of issues with the script
first off, your stamina is a value inside the script not a numbervalue stored in a folder inside Player instance
second, you are doing it all inside a local script, meaning i could just edit the script and set my stamina to 99999999999
thirdly you are relying on property signal change
Exactly my point. How will other scripts interact with it? This is why numbervalues exist. You store the value there so that all other scripts can know how much stamina a player has
either way it’s a bad idea to keep it in a local script. You should be doing this in a server script. For which you would then need a number value to communicate between local and server script