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

What's wrong with this script?

local debounce = false

function onTouch(hit)
	if debounce == true then return end
		debounce = true
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		if humanoid then
			local message = Instance.new("Hint",game.Workspace)
			for i=10,0,-1 do
				message.Text = i..
				wait(1)
				debounce = false
		end
	end
end

script.Parent.Touched:connect(onTouch)
message:remove()

The script keeps repeating from 10 every time the brick is touched. What's the issue with it?

2 answers

Simple,you set the individual pair "I to 10,0,-1 all you have to do is change the i pairs assigned number to a lower number and the denounce to true maybe then it won't have to repeat the script.

1 comment

0

debounce*

The problem is that you are disabling the debounce too early. Instead of disabling it inside the for loop, disable it afterwards. You also should destroy the message inside the touched handler. It doesn't exist outside the scope of the touch handler:

local debounce = false

function onTouch(hit)
	if debounce then return end
	debounce = true
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local message = Instance.new("Hint",game.Workspace)
		for i=10,0,-1 do
			message.Text = i --Edit: Remove the ellipsis from this line
			wait(1)
		end
		debounce = false
		message:Destroy()
	end
end

script.Parent.Touched:connect(onTouch)

This will prevent the function from executing again until the countdown is finished.

Edit: Removed an ellipsis on line 10

2 comments

0

I tried that script. It didn't work.

0

Try it now. I tried it. It works.

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