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

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

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

✓ Accepted answer

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.

1 comment

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.

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