If loop going through despite debounce being false?

I’m making a script that drops your health to just 10, everything is going fine except for the fact that the if loop still goes through despite debounce being false, am I doing something wrong?

local brick = script.Parent
local debounce = true

brick.Touched:Connect(function(person)
	local Humanoid = person.Parent:FindFirstChild("Humanoid")
	local Robloxian = person.Parent
	if Humanoid and debounce == true then
		debounce = false
		print("Health Dropped!")
		Humanoid.Health = 10
		debounce = true
	else 
		return
	end
end)

Your debounce is basically instant.
add a delay.

local brick = script.Parent
local debounce = true

brick.Touched:Connect(function(person)
	local Robloxian = person.Parent
	local Humanoid = Robloxian:FindFirstChild("Humanoid")
	if Humanoid and debounce then
		debounce = false
		print("Health Dropped!")
		Humanoid.Health = 10
		task.delay(0.1, function()
			debounce = true
		end)
	end
end)
1 Like

I’m dumb. Thank you very much.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.