I’ve tried revising this script a countless amount of times and nothing works. Here is what I have, apologies if it’s messy or unnecessary complicated. No errors are being outputted. It looks like it’ll go in a loop, not sure if it will but even without the elseif part it doesn’t work.
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.ImageTransparency == 0.8 then
script.Parent.Parent.ImageTransparency = 0
elseif script.Parent.Parent.ImageTransparency == 0 then
script.Parent.Parent.ImageTransparency = 0.8
end
end)
Decimal comparisons will seldom be accurate, try something like
-- (modified code to work without if statements just to make it shorter for demonstration)
local obj = script.Parent
local function onClicked()
obj.ImageTransparency = obj.ImageTransparency >= 0.8 and 0 or 0.8
end
script.Parent.Activated:Connect(onClicked)
There’s inconsistencies and floating point errors while comparing and performing arithmetic operations on decimal numbers in Lua.