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

How would you make a model go invisible But then make another visible when clicked?

Asked by 8 years ago

At the moment i have This

Box1 = script.Parent

function turnGhostly()
if Box1.Transparency == 0 then
Box1.Transparency = 0.5 
end
end

Box1.ClickDetector.MouseClick:connect(t­urnGhostly)

But how Would i go about making this for a model and not just a brick and how would i make it switch on another model? Like this --Model one --Model two

to --Model one --model two

Bold Model is the one that is not Transparent.

Don't know if this makes very much sense first time posting here; so let me know if i should improve my question.

2 answers

Log in to vote
0
Answered by
theCJarmy7 1293 Moderation Voter
8 years ago

you would do that like this:

box = script.Parent
box2 = game.Workspace:FindFirstChild("Model2")

box.ClickDetector.MouseClick:connect(function() -- connection line and makes the function all in one
    for i,v in pairs(box:GetChildren()) do -- v now equals all the children of box
        wait()
        if v.Transparency then -- the clickdetector is inside the model, so it will only do this if v(the current child) has the transparency property
        if v.Transparency == 0 then
box2.Transparency = 0
            v.Transparency = .5
        else v.Transparency = 0 -- if it's not 0, then make it 0
box2.Transparency = .5
            end
end
end
end)

and ta-da, if you don't know what all of these things that have been used are, check the wiki.

also, if you want box2 to be clickable as well, just change the variables a little

0
Hey thanks for the quick answer I'm not very experienced at scripting i tired it out it Is gives me an error back saying Transparency is not a valid member of Model So how would i got about adding the transparency property. Brettfluffy2 0 — 8y
0
what line? theCJarmy7 1293 — 8y
0
and whats the scripts parent, if the script isn't in the model, then i know what the issue is theCJarmy7 1293 — 8y
Ad
Log in to vote
0
Answered by
Tynezz 0
8 years ago

The other code is highly inefficient.

local box=script.Parent
local visibleBox=--path to box that will become visible;

box.ClickDetector.MouseClick:connect(function()
    --Make the parts invisible
    for index,value in pairs(box:GetChildren()) do --So what we are doing here is looping through each part, making value the current part
        if value:IsA'BasePart' then --Checking if it's a part
            value.Transparency=1
        end
    end

    --Make the visibleBox visible
    for index,value in pairs(visibleBox:GetChildren()) do
        if value:IsA'BasePart' then
            value.Transparency=0
        end
    end
end)

--[[
Also, if you don't know about Transparency, it's a integer that is between 0 and 1. If you want it a higher number just do something like this: Transparency=1/num

Also, transparency is like a bar, when it's at 1, it's fully visible while at 0 it's completely invisible.
]]

Answer this question