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

Anyone know how to disable a ClickDetector?

I am making a farming button. But I want to prevent spams while the wheat is regrowing. Is there anyway I can disable the ClickDetector when the wheat has grown again? This is my code:

function onClicked(player)
game.Players:FindFirstChild(player.Name).leaderstats.Coins.Value = game.Players:FindFirstChild(player.Name).leaderstats.Coins.Value + 100
game.Players.thenasafarouk.leaderstats.Coins.Value = game.Players.thenasafarouk.leaderstats.Coins.Value + 20
--I want to disable it here
game.Workspace.WheatSix.Transparency = 1
game.Workspace.WheatFive.Transparency = 1
game.Workspace.WheatFour.Transparency = 1
game.Workspace.WheatThree.Transparency = 1
game.Workspace.WheatTwo.Transparency = 1
game.Workspace.WheatOne.Transparency = 1
wait(60)
game.Workspace.WheatSix.Transparency = 0
game.Workspace.WheatFive.Transparency = 0
game.Workspace.WheatFour.Transparency = 0
game.Workspace.WheatThree.Transparency = 0
game.Workspace.WheatTwo.Transparency = 0
game.Workspace.WheatOne.Transparency = 0
end
--Then I want to enable it here
script.Parent.ClickDetector.MouseClick:connect(onClicked)

Thanks, thenasafarouk

1 answer

✓ Accepted answer

This would call for a debounce. Here's your remodified script:

local debounce = true

function onClicked(player)
if debounce == true then
game.Players:FindFirstChild(player.Name).leaderstats.Coins.Value = game.Players:FindFirstChild(player.Name).leaderstats.Coins.Value + 100
game.Players.thenasafarouk.leaderstats.Coins.Value = game.Players.thenasafarouk.leaderstats.Coins.Value + 20
debounce = false
game.Workspace.WheatSix.Transparency = 1
game.Workspace.WheatFive.Transparency = 1
game.Workspace.WheatFour.Transparency = 1
game.Workspace.WheatThree.Transparency = 1
game.Workspace.WheatTwo.Transparency = 1
game.Workspace.WheatOne.Transparency = 1
wait(60)
game.Workspace.WheatSix.Transparency = 0
game.Workspace.WheatFive.Transparency = 0
game.Workspace.WheatFour.Transparency = 0
game.Workspace.WheatThree.Transparency = 0
game.Workspace.WheatTwo.Transparency = 0
game.Workspace.WheatOne.Transparency = 0
debounce = true
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

3 comments

0

Yea I got it. But what I did is that I changed the MaxActivationDistance

0

Ah, okay.. if you need any help with any scripts you can message me on ROBLOX. I'm very experienced.

0

Does it really need to be called debounce ? Or can it be called anything you want

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