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

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

Asked by 10 years ago

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

1function click()
2script.Parent.Parent["Moving Office Chair"].Transparency = 0.8
3script.Parent.Parent["Moving Office Chair"].CanCollide = false
4 
5script.Parent.ClickDetector.MouseClick:connect(click)
1function click()
2script.Parent.Parent["Moving Office Chair"].Transparency = 0
3script.Parent.Parent["Moving Office Chair"].CanCollide = true
4 
5script.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.

1
Your title and content are contradictory. You are asking two different questions. User#2263 0 — 10y
0
Thank you, I fixed it. Laserpenguin12 85 — 10y

2 answers

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

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

01visible = true
02script.Parent.ClickDetector.MouseClick:connect(function()
03    if visible == true then
04        for i,v in pairs(script.Parent.Parent["Moving Office Chair"]:GetChildren()) do
05            v.Transparency = 0.8 -- 1 is for completely invisible
06            v.CanCollide = false
07            visible = false
08        end
09    elseif visible == false then
10        for i,v in pairs(script.Parent.Parent["Moving Office Chair"]:GetChildren()) do
11            v.Transparency = 0
12            v.CanCollide = true
13            visible = true
14        end
15    end
16end)
Ad
Log in to vote
0
Answered by 10 years ago

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.

Answer this question