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

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

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

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

3 comments

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.

0

what line?

0

and whats the scripts parent, if the script isn't in the model, then i know what the issue is

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.
]]

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