Ad
Log in to vote
0

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

Asked by 7 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

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.

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

2 answers

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

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)
Ad
Log in to vote
0
Answered by 7 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