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

How would I make it so that when I click a block it disappears and comes back after some time?

Asked by 4 years ago

I tried making this but it didnt work. It disappeared and came back but nothing happened when I clicked it.

My code:

01script.Parent.ClickDetector.MouseClick:Connect(function(player)
02    script.Parent.Transparency = 1
03    script.Parent.CanCollide = false
04    script.Parent.ClickDetector:Destroy()
05    wait(10)
06    script.Parent.Transparency = 0
07    script.Parent.CanCollide = true
08    local click = Instance.new("ClickDetector")
09    click.Parent = script.Parent
10end)

Please help!

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
4 years ago
Edited 4 years ago

Rather than destroying the click detector, what I'd do is make it a variable and parent it elsewhere until you need to use it again.

01local clickDetector = script.Parent.ClickDetector
02 
03clickDetector.MouseClick:Connect(player)
04    script.Parent.Transparency = 1
05    script.Parent.CanCollide = false
06    clickDetector.Parent = game.ServerStorage
07    wait(10)
08    script.Parent.Transparency = 0
09    script.Parent.CanCollide = true
10    clickDetector.Parent = script.Parent
11end)

Obviously you can parent it where ever you need but in hindsight I feel it's a lot easier than destroying it and then creating a new one.

0
Yoy could also just change the selection distance to 0 and it would do the same thing, withput having to move the click detector. gwenniekins 59 — 4y
Ad

Answer this question