Does not disallow jump when stamina is at 0

so it used to work before but it never works when i try to add a debounce into the script

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 db = false
local isJumping = false

local uis = game:GetService("UserInputService")


humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
	if db == false and stamina > 0 then
		isJumping = true
		db = true
		wait(0.5)
		db = false
		if isJumping then
			humanoid.JumpPower = 50
			wait()
		end
	end
end)


while wait() do

	if stamina == 0 and isJumping then
		isJumping = false
		db = true
		humanoid.JumpPower = 0
		wait(5)
		db = false
		humanoid.JumpPower = 50
	end


	if isJumping then
		humanoid.JumpPower = 50
		stamina -= 20
		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

Your problem is that the isJumping value only updates after the character jumps.

can you elaborate on that im still confused

im sure the problem has to be at the first bit since it only breaks like that when i add debounce there

Sorry, got a little mixed up between posts.

Anyways, did you check if the stamina is indeed going down?

yes the stamina goes down, it just doesnt stop the player from jumping when it hits 0

Been re-reading it for like 10 mins now, try to put

spawn(function()
db = true
wait(0.5)
db = false
end

where do i put this and wat is spawn for

are u still there or are u not

Yeah I’m right here, just went for a bit.
Anyways, you put it inside here:

humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
	if db == false and stamina > 0 then
		isJumping = true
		spawn(function()
        db = true
		wait(0.5)
		db = false
         end
		if isJumping then
			humanoid.JumpPower = 50
			wait()
		end
	end
end)

It creates a separate thread.

do i replace anything or i just paste it in

Replace it with this part of the script

1 Like

now it just sorta doesnt move the stamina bar

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 db = false
local isJumping = false

local uis = game:GetService("UserInputService")


spawn(function()
	db = true
	wait(0.5)
	db = false
end)



while wait() do

	if stamina == 0 and isJumping then
		isJumping = false
		db = true
		humanoid.JumpPower = 0
		wait(5)
		db = false
		humanoid.JumpPower = 50
	end


	if isJumping then
		humanoid.JumpPower = 50
		stamina -= 20
		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

:man_facepalming: ok I probably wasn’t clear enough
put

humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
	if db == false and stamina > 0 then
		isJumping = true
		spawn(function()
        db = true
		wait(0.5)
		db = false
         end
		if isJumping then
			humanoid.JumpPower = 50
			wait()
		end
	end
end)

instead of what you pasted

Right here, instead of saying “if IsJumping”, I recommend you say “if isJumping == true then”
so you can do an else for it not jumping.

it still doesnt disallow jump when it reaches 0

ok ill try to do that right now

No, if (value) for any bool will only pass if it is true. You can test this out yourself.

yea it still isnt disabling jump

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 db = false
local isJumping = false

local uis = game:GetService("UserInputService")

humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
	if db == false and stamina > 0 then
		isJumping = true
		spawn(function()
			db = true
			wait(0.5)
			db = false
		end)
		if isJumping then
			humanoid.JumpPower = 50
			wait()
		end
	end
end)

while wait() do

	if stamina == 0 and isJumping then
		isJumping = false
		db = true
		humanoid.JumpPower = 0
		wait(5)
		db = false
		humanoid.JumpPower = 50
	end


	if isJumping == true then
		humanoid.JumpPower = 50
		stamina -= 10
		isJumping = false
		wait()
	elseif isJumping == false then
		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

Jumped the shark a bit soon, oops. Roblox Battle has a similar stamina script if ya wanna check that out.
jump_limiter.rbxm (3.5 KB)

OG Reply

Could using Humanoid.Jumping perhaps be a solution? It could be used to detect when the player’s jumping and subtract from the stamina, then in another while loop it increases the stamina. For example,

local Stamina = 100

Humanoid.Jumping:Connect(function(IsJumping)
    if IsJumping then
        Stamina -= 20
        if Stamina < 0 then
            -- Disable jumping
        end
    end
end)

while true do
    Stamina += 10
    if Stamina > 0 then
        -- Renable jumping
    end
    wait(1)
end

I hope this helped. :slight_smile:

EDIT

Open up Roblox studio - you can open up a blank baseplate if ya want. Right click on ServerStorage and select Insert from file. If your browser defaults your downloaded files to your Downloads folder, it’ll be there. Find the file amongst your other files and double click to insert it. :slight_smile:

EDIT2

I recommend examining/reverse engineering how Games wrote it. It uses a debounce also, so I think it’d be a worthy read. :smile:

2 Likes