Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

(SOLVED) Debounce stops code from running at all?

I'm creating a little touch part to demonstrate a database system, the idea being every time you touch the part you get 5 points. Since the roblox touch system is a bit finnicky, I need a debounce which is pretty simple. My code is as follows;

local debounce = true
TestPart.Touched:Connect(function(Part)
if debounce == true then
		debounce = false
		print('ok')


	if Part.Parent:FindFirstChild('HumanoidRootPart') then
		
-- code is here

		end
		wait(5)
		debounce = true
	end
end)

When I touch this part the code doesn't run at all. Why is this happening and how can I solve it?

4 comments

0

what type of script is this, and where is it located?

0

Normal script in workspace

0

Is the script disabled? Did you specify a variable for the part in question?

0

can you add the variable TestPart in the question?

3 answers

i use this code to test your code. And it works. Try to change the parameter to hit and btw i put this code inside the part

local TestPart = workspace.Part
local debounce = true
TestPart.Touched:Connect(function(hit)
		if debounce == true then
		debounce = false
		print('ok')
		if hit.Parent:FindFirstChild('HumanoidRootPart') then
			
			print("HumanoidPart")
			
		end
		wait(5)
		debounce = true
	end
end)

1 comment

0

You don't have to change the parameter to hit, it doesn't matter.

It seems to me that your script is touching other non-humanoid parts so debounce is false at all times. Try only changing the debounce after a HumanoidRootPart is found.

Setting the part collision to off seemed to do the trick.

This discussion is preserved as it was. New answers, comments, and votes are closed.