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

How to make ClickDetector have Multiple Functions?

Asked by 3 years ago

So this has been stuck in my head all day and I know it is obviously possible, but I don't know how to do it. Let's say I have a Click Detector on a "Part". Now, if I click this part, I want it to change the Can Collide to false and the Transparency to 0.5. Simple code. But, now, if I click it again, I want those properties to go back to Can Collide being true and the Transparency being false. So, how would I achieve that? Thanks for your help!

1 answer

Log in to vote
1
Answered by
Vathriel 510 Moderation Voter
3 years ago

Well this is simply achievable with a boolean flag and an if statement.

local Open = false

clickdetector.MouseClick:connect(function()
    if Open == false then
        Open = true
        part.Transparency = 0.5
        part.CanCollide = false
    else
        Open = false
        part.Transparency = 0
        part.CanCollide = true
    end
end)
Ad

Answer this question