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 3 years ago

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

My code:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    script.Parent.Transparency = 1
    script.Parent.CanCollide = false
    script.Parent.ClickDetector:Destroy()
    wait(10)
    script.Parent.Transparency = 0
    script.Parent.CanCollide = true
    local click = Instance.new("ClickDetector")
    click.Parent = script.Parent
end)

Please help!

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
3 years ago
Edited 3 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.

local clickDetector = script.Parent.ClickDetector

clickDetector.MouseClick:Connect(player)
    script.Parent.Transparency = 1
    script.Parent.CanCollide = false
    clickDetector.Parent = game.ServerStorage
    wait(10)
    script.Parent.Transparency = 0
    script.Parent.CanCollide = true
    clickDetector.Parent = script.Parent
end)

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 — 3y
Ad

Answer this question