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.

01local part = script.Parent
02 
03local function Clicked(playerWhoClicked)
04    if part.Transparency == .9 then
05        part.Transparency = 0
06    else
07        part.Transparency = .9
08    end
09end
10 
11 
12 
13 
14 
15 
16 
17 
18script.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:-

01local part = script.Parent
02 
03local 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
10end
11 
12script.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

01local part = script.Parent
02 
03local function Clicked(playerWhoClicked)
04    if part.Transparency == 0 then -- logic swapped
05        part.Transparency = .9
06    else
07        part.Transparency = 0
08    end
09end
10 
11script.Parent.ClickDetector.MouseClick:connect(Clicked)

Hope this helps.

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

Answer this question