Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What's wrong with this script?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
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

Log in to vote
0
Answered by 10 years ago

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.

0
debounce* legomaster38 39 — 10y
Ad
Log in to vote
0
Answered by
AxeOfMen 434 Moderation Voter
10 years ago

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

0
I tried that script. It didn't work. atechdecks 10 — 10y
0
Try it now. I tried it. It works. AxeOfMen 434 — 10y

Answer this question