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

How to I make a MODEL disappear and reappear using ClickDetector?

How do I make a model disappear and reappear using ClickDetector? This is what I did on the first script, then the second script

function click()
script.Parent.Parent["Moving Office Chair"].Transparency = 0.8
script.Parent.Parent["Moving Office Chair"].CanCollide = false

script.Parent.ClickDetector.MouseClick:connect(click)
function click()
script.Parent.Parent["Moving Office Chair"].Transparency = 0
script.Parent.Parent["Moving Office Chair"].CanCollide = true

script.Parent.ClickDetector.MouseClick:connect(click)

I'm guessing it's the problem where ["Moving Office Chair"] is. Also, this is a model, not a part.

2 comments

1

Your title and content are contradictory. You are asking two different questions.

0

Thank you, I fixed it.

2 answers

✓ Accepted answer

If it's a model, you'd need to use the GetChildren method and I'd recommend using a 'for' loop.

visible = true
script.Parent.ClickDetector.MouseClick:connect(function()
	if visible == true then
		for i,v in pairs(script.Parent.Parent["Moving Office Chair"]:GetChildren()) do
			v.Transparency = 0.8 -- 1 is for completely invisible
			v.CanCollide = false
			visible = false
		end
	elseif visible == false then
		for i,v in pairs(script.Parent.Parent["Moving Office Chair"]:GetChildren()) do
			v.Transparency = 0
			v.CanCollide = true
			visible = true
		end
	end
end)

Recurse through the descendants of the model and set each part to transparent. You will need to check if each descendant is a Part, WedgePart... before you try to set the transparency to avoid errors. Plese see this page for information about recursion.

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