If Statements! Inside of your function you can make a check to see if CanCollide is true or false, and change what happens to your part depending on this. You'll want something like this:
script.Parent.ClickDetector.MouseClick:connect(function()
script.Parent.CanCollide = not script.Parent.CanCollide
end)
It's pretty easy to follow and read, If script.Parent.CanCollide is true, then script.Parent.CanCollide is set to false, and vice versa.
If you'd like to keep that 10 second wait time, it gets a little more complicated. You'll have to set up another function to activate after your first check is made, wait 10 seconds, and then make another check to see if anything needs to be changed. Something like this:
local function timer()
wait(10)
if script.Parent.CanCollide == false then
script.Parent.CanCollide = false
end
end
script.Parent.ClickDetector.MouseClick:connect(function()
script.Parent.CanCollide = not script.Parent.CanCollide
timer()
end)
2 comments
An easier way of doing this is "script.Parent.CanCollide = not script.Parent.CanCollide" to replace lines 9 to 13.
Thats correct, Ill edit my code.