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

Why wont this click detector script work?

Asked by 9 years ago

bell = script.Parent function clickit() bell.ClickDetector:Destroy() wait(20) Instance.new("ClickDetector", bell) end bell.ClickDetector.MouseClick:connect(clickit)

This should make it so after you click the bell it removes the click detector for 20 seconds and puts a new one. It works the first time but after that I doesn't remove it.

0
2 years later you accept my answer. GG Shawnyg 4330 — 7y

1 answer

Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

Instead of removing the ClickDetector, you can access the MaxActivationDistance property. So:

bell = script.Parent
activated = false

function clickit()
    if activiated == false then
        activated = true -- I recommend setting a debounce in-case a player or more clicks it multiple times.
        bell.ClickDetector.MaxActiviationDistance = 0
        wait(20)
        bell.ClickDetector.MaxActiviationDistance = 32 -- The default distance I believe
        activated = false
    end
end

bell.ClickDetector.MouseClick:connect(clickit)
Ad

Answer this question