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

Transparent and CanCollide Toggle Button? (Help!)

Asked by 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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

0
Thank you! But I was wondering, could it be a button for another object. Like the button works something else. Like a model lincolnjones1 2 — 3y
0
yeah but idk what you will do with that, tell me acediamondn123 147 — 3y
Ad
Log in to vote
2
Answered by
2_MMZ 1059 Moderation Voter
3 years ago

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)
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

0
Exactly what I want. Would it be possible for a button instead of a GUI Button? lincolnjones1 2 — 3y
0
Oh sorry, i thought it was for a gui button. xxoplol47811t 34 — 3y

Answer this question