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

How can I make each part touched only once using debounce?

Let's say that I made a hitbox. Five parts are touching the hitbox. Each part will be touched only once. If the hitbox touches that part again, the code wouldn't run on it. Are there any efficient ways of doing that?

1 answer

You can have a variable for each part called, for example, "enabled". You can default the variables to true. In the Touched event, you can check if the variables are true using if statements. Then, inside of the if statements, after the rest of your code, set the variables to false. This way, the code will only run the first time the part is touched. Your code would look something like this:

local enabled = true

part.Touched:Connect(function()
	if enabled then
		--code
		enabled = false
	end
end)

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