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

Why it prints but can't make the Part CanCollide to false?

Asked by 3 years ago
Edited 3 years ago
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)

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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)
0
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 BlackFateX 19 — 3y
Ad

Answer this question