How do I make a model disappear and reappear using ClickDetector? This is what I did on the first script, then the second script
1 | function click() |
2 | script.Parent.Parent [ "Moving Office Chair" ] .Transparency = 0.8 |
3 | script.Parent.Parent [ "Moving Office Chair" ] .CanCollide = false |
4 |
5 | script.Parent.ClickDetector.MouseClick:connect(click) |
1 | function click() |
2 | script.Parent.Parent [ "Moving Office Chair" ] .Transparency = 0 |
3 | script.Parent.Parent [ "Moving Office Chair" ] .CanCollide = true |
4 |
5 | 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.
If it's a model, you'd need to use the GetChildren method and I'd recommend using a 'for' loop.
01 | visible = true |
02 | script.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 |
16 | 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.