local s = script.Parent -- the Parent is a Part that has ClickDetector as a Child.
script.Parent.ClickDetector.MaxActivationDistance = 8
local a = 1
script.Parent.ClickDetector.MouseClick:Connect(function ()
print("clicked")
if a == 1 then -- I wanted this to be worked when first clicked,but never worked.
a = 0
s.Transparency = 0.7
s.CanCollide = false
end
if a == 0 then
a = 1
s.Transparency = 0
s.CanCollide = true
end
end)
✓ ANSWER ACCEPTED
Why it prints but can't make the Part CanCollide to false?
1 answer
✓ Accepted answer
The problem is, that you have two if. So firstly, it check if a=1, and if it is, it sets to cancollide false and transparency 0.7. But the problem is that it sets to a=0, and stops the first if. Then comes the second if, and the a currently is 0, because it was setted to 0 at the first if. And runs the second if, then sets back to cancollide true and transparency 0 So you just need one if, and then a elseif, not two if. Here, try this:
local s = script.Parent -- the Parent is a Part that has ClickDetector as a Child.
script.Parent.ClickDetector.MaxActivationDistance = 8
local a = 1
script.Parent.ClickDetector.MouseClick:Connect(function ()
print("clicked")
if a == 1 then -- I wanted this to be worked when first clicked,but never worked.
a = 0
s.Transparency = 0.7
s.CanCollide = false
elseif a == 0 then
a = 1
s.Transparency = 0
s.CanCollide = true
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
set the local s = script.Parent -- the Parent is a Part that has ClickDetector as a Child. code into it, it did not putted into it