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

I've wrote a script which should trigger something when it's clicked but it isn't working?

Asked by
cgk255 2
4 years ago

Hiya, I was wondering if anyone could help me out with this. I've typed this script, however, when I go into testing mode nothing happens.

Any help would be greatly appreciated.

function OnClick()
    if script.Parent.Parent.Parent.LEDDisplay.End.uni0045.Transparency == 0.98 then
    script.Parent.Parent.Parent.LEDDisplay.End.uni0045.Transparency = 0
    script.Parent.Parent.Parent.LEDDisplay.End.uni0064.Transparency = 0
    script.Parent.Parent.Parent.LEDDisplay.End.uni006E.Transparency = 0
elseif script.Parent.Parent.Parent.LEDDisplay.End.uni0045.Transparency == 0 then
    script.Parent.Parent.Parent.LEDDisplay.End.uni0045.Transparency = 0.98
    script.Parent.Parent.Parent.LEDDisplay.End.uni0064.Transparency = 0.98
    script.Parent.Parent.Parent.LEDDisplay.End.uni006E.Transparency = 0.98
    end
end
script.Parent.ClickDetector.MouseClick:Connect(OnClick)

Thanks

0
It's because of floating precision (https://www.youtube.com/watch?v=PZRI1IfStY0). Even though you're telling your script to check Transparency to 0.98, the Transparency property may actually be 0.98000001907349 thus invalidating your selection. A way to mitigate this may be to simply multiply your value by 100, take a floor of the new value and do a comparison of an integer to an integer. M39a9am3R 3210 — 4y
0
Ah, I got it now, thanks for the help. cgk255 2 — 4y

Answer this question