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

Trying to make a part become Non see through when clicked?

Asked by 8 years ago

Trying to make windows become non see through when clicked. The clicker shows up and such, but nothing happens to the window.

local part = script.Parent

local function Clicked(playerWhoClicked)
    if part.Transparency == .9 then
        part.Transparency = 0
    else
        part.Transparency = .9
    end
end








script.Parent.ClickDetector.MouseClick:connect(Clicked)
0
Have you checked if the window's transparency is actually 0.9? SHDrivingMeNuts 299 — 8y
0
Yes I have. In fact I was going to use this to all my windows which are all .9 barkface1 15 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

When debugging code it is good to find out the value:-

local part = script.Parent

local function Clicked(playerWhoClicked)
    print(part.Transparency) -- simple print
    if part.Transparency == 0.9 then
        part.Transparency = 0
    else
        part.Transparency = .9
    end
end

script.Parent.ClickDetector.MouseClick:connect(Clicked)

Output:-

0.89999997615814

The problem

Floating points. As sown in the example the code will never be able to compare to 0.9

The simplest solution

Just invert your logic

local part = script.Parent

local function Clicked(playerWhoClicked)
    if part.Transparency == 0 then -- logic swapped
        part.Transparency = .9
    else
        part.Transparency = 0
    end
end

script.Parent.ClickDetector.MouseClick:connect(Clicked)

Hope this helps.

0
Yeah it did. Thanks barkface1 15 — 8y
Ad

Answer this question