Hey everyone!
I have started working on a game recently where you can destroy and crops and wait for them to regenerate. However, I am facing issues getting the ClickDetector
to work on the crop once it has regenerated. Is there some way that I can fix this problem?
Here is my code:
brick = script.Parent
local click = Instance.new("ClickDetector")
click.MaxActivationDistance = 10
click.Parent = brick
function Click()
brick.Transparency = 1
brick.ClickDetector:Destroy()
if brick.Transparency == 1 then
local random_amount = math.random(6, 15)
print(random_amount)
wait(random_amount)
brick.Transparency = 0
local click_detector = Instance.new("ClickDetector")
click_detector.MaxActivationDistance = 10
click_detector.Parent = brick
end
end
brick.ClickDetector.MouseClick:connect(Click)
Any help is appreciated!
Thank You.