Trying to make windows become non see through when clicked. The clicker shows up and such, but nothing happens to the window.
01 | local part = script.Parent |
02 |
03 | local function Clicked(playerWhoClicked) |
04 | if part.Transparency = = . 9 then |
05 | part.Transparency = 0 |
06 | else |
07 | part.Transparency = . 9 |
08 | end |
09 | end |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | script.Parent.ClickDetector.MouseClick:connect(Clicked) |
When debugging code it is good to find out the value:-
01 | local part = script.Parent |
02 |
03 | local function Clicked(playerWhoClicked) |
04 | print (part.Transparency) -- simple print |
05 | if part.Transparency = = 0.9 then |
06 | part.Transparency = 0 |
07 | else |
08 | part.Transparency = . 9 |
09 | end |
10 | end |
11 |
12 | 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
01 | local part = script.Parent |
02 |
03 | local function Clicked(playerWhoClicked) |
04 | if part.Transparency = = 0 then -- logic swapped |
05 | part.Transparency = . 9 |
06 | else |
07 | part.Transparency = 0 |
08 | end |
09 | end |
10 |
11 | script.Parent.ClickDetector.MouseClick:connect(Clicked) |
Hope this helps.