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

Why does it keep printing "Touched" when I touched it once?

Alright, so I have a script that is supposed to print "Touched" once when a player steps on it once, but it keeps duplicatin' the message as fast as hell. Here's my script.

local part = script.Parent

part.Touched:Connect(function(onTouchPart)
	print("Touched")
end)

It's a Script parented to a Part in the Workspace.

I'll be waitin' for answers, y'all.

1 answer

✓ Accepted answer

You can fix this by adding debounce, here is a quick fix to prevent this.

local part = script.Parent
local debounce = false

part.Touched:Connect(function(onTouchPart)
	if debounce = false then

	debounce = true
	print("Touched")
	wait(3)
	debounce = false

	end
end)

What we are basically doing here is adding a debounce (small wait duration) to the code to prevent it from spamming.

3 comments

1

NOOOOOOO, theres a reason why CanTouch exists

1

Yeah, just disable CanTouch, it's practically an in-game debounce.

0

Thanks for helping you three! I appreciate your answers that they resolved my problem!

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