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

Why isn't debounce working on Clickdetector?

I have been trying on and on to getting a clickdetector to work once before a timer stops and is clickable again. I tried for a really long time yesterday until finally I am getting help here. Anyways heres the script:

clicker = script.Parent
local debounce = true
clicker.ClickDetector.MouseClick:Connect(function(player)
	if debounce == true then
		debounce = false
		wait(2)
		local models = game.Lighting.Models:GetChildren()
		local randomModel = models[math.random(1,#models)]
		local modelClone = randomModel:Clone()
		modelClone.Parent = game.Workspace
		wait(20)
		debounce = true
end)

2 comments

0

Are you using filtering enabled and are you using remote events? Click detectors won't work on filtering enabled without a remote event.

0

can you help me with that?

2 answers

✓ Accepted answer

Copy and paste this code into your script.

clicker = script.Parent
local debounce = true
clicker.ClickDetector.MouseClick:Connect(function(player)
    if debounce == true then
        debounce = false
        wait(2)
        local models = game.Lighting.Models:GetChildren()
        local randomModel = models[math.random(1,#models)]
        local modelClone = randomModel:Clone()
        modelClone.Parent = game.Workspace
        wait(20)
        debounce = true
    end
end)

If it doesn't work, make sure you're referring to the ClickDetector, you could be accidentally putting the Script in the ClickDetector.

#Simple fix:

You forgot an end at the end of the if statement.

#Shorten your code:

You could actually just do:

if debounce then
	--CODE HERE
end

1 comment

0

it didn't work

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