|
| 25 Jun 2015 08:21 PM |
I want the script so when its clicked you cant click it for 10 seconds and then you can click it again. after i click it once it will destroy the clicker than make a new one. but after its destroyed and there is a new one created it wont get destroyed again once clicked
function onClicked(onClicked) script.Parent.ClickDetector:Destroy() wait(10) Instance.new("ClickDetector", script.Parent) script.Parent.ClickDetector.Name = "ClickDetector" end script.Parent.ClickDetector.MouseClick:connect(onClicked)
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 25 Jun 2015 08:22 PM |
local debounce = false
if not debounce then debounce = true --code wait(10) debounce = false end |
|
|
| Report Abuse |
|
|
|
| 25 Jun 2015 08:23 PM |
sorry this is one without the pointless part
function onClicked(onClicked) script.Parent.ClickDetector:Destroy() wait(10) Instance.new("ClickDetector", script.Parent) end script.Parent.ClickDetector.MouseClick:connect(onClicked)
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
Ictis
|
  |
| Joined: 01 Sep 2011 |
| Total Posts: 1216 |
|
|
| 25 Jun 2015 08:41 PM |
| That's because you're removing the click detector when it's clicked. |
|
|
| Report Abuse |
|
|
|
| 25 Jun 2015 08:43 PM |
| is there a way for it to work if i'm removing the ClickDetector |
|
|
| Report Abuse |
|
|
Ictis
|
  |
| Joined: 01 Sep 2011 |
| Total Posts: 1216 |
|
|
| 25 Jun 2015 08:47 PM |
cd = script.Parent.ClickDetector function onClicked(onClicked) script.Parent.ClickDetector:Destroy() wait(10) cd = Instance.new("ClickDetector", script.Parent) end cd.MouseClick:connect(onClicked) |
|
|
| Report Abuse |
|
|
|
| 25 Jun 2015 08:49 PM |
It breaks cause you'd need another event line for the new ClickDetector; but as everyone else is suggesting, just use debounce...
local debounce = coroutine.create(function() wait(10) end)
script.Parent.ClickDetector.MouseClick:connect(function() if coroutine.running() == debounce then return end coroutine.resume(debounce) --code end)
That's for if your script has wait() as well or something, but otherwise, do this:
local debounce = false
script.Parent.ClickDetector.MouseClick:connect(function() if debounce then return end debounce = true --code wait(10) debounce = false end) |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2015 03:51 AM |
function onClicked() script.Parent.ClickDetector.MaxActavtionDistance = 0 wait(10) script.Parent.ClickDetector.MaxActavtionDistance = 32 end script.Parent.ClickDetector.MouseClick:connect(OnClicked)
these may work i did not test it |
|
|
| Report Abuse |
|
|