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

Transparent and CanCollide Toggle Button? (Help!)

Okay so,

i know this may sound really simple but,

I have a theatre game and it has a stage with different sets, I currently change it all manually but I think I can get a script to do it for me.

So, I want a button that you can click that makes a model go transparent and you can walk thru it, like it is not there (i think that is cancollide false). And then if you click the button again, it is back (non-transparent and cancollide true)

Yea hope that you can understand!

cheers!

3 answers

✓ Accepted answer

Oh just put a "ClickDetector" in your part and add a script inside the "ClickDetect" containing this code:

script.Parent.MouseClick:Connect(function()
	local part = script.Parent.Parent
	
	part.Transparency = 1
	part.CanCollide = false
end)

however, if you want it to be opened and closed use this one:

local open = false -- a variable to define if its open or not

script.Parent.MouseClick:Connect(function()
	local part = script.Parent.Parent
	
	if open then -- if open or if open == true
		open = false -- we set it to false so it doesnt do the same code
		
		part.Transparency = 1
		part.CanCollide = false
	else -- you prob get this one lol
		part.Transparency = 0
		part.CanCollide = true
	end
end)

hope I helped

2 comments

0

Thank you! But I was wondering, could it be a button for another object. Like the button works something else. Like a model

0

yeah but idk what you will do with that, tell me

This can be simply solved by inputting a ClickDetector inside of your target part. Next, in that same very part, insert a Script. Then, type the following code:

script.Parent.ClickDetector.MouseClick:Connect(function()
       script.Parent.Transparency = 1
script.Parent.CanCollide = false
end)

I have made a quick video on how to do this, and I will also give you the roblox game as I published it to roblox, and you will be able to get a copy of the game if you click the 3 dots next to the game title. Also where it says model = just put where your model is in the explorer. for e.g.

game.workspace.House.Jimmy

or something like that.

Video: https://youtu.be/JycJWLYSXGI

Game: https://www.roblox.com/games/6738511109/Model-with-Button

2 comments

0

Exactly what I want. Would it be possible for a button instead of a GUI Button?

0

Oh sorry, i thought it was for a gui button.

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