Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

0

Have you checked if the window's transparency is actually 0.9?

0

Yes I have. In fact I was going to use this to all my windows which are all .9

1 answer

✓ Accepted answer

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.

1 comment

0

Yeah it did. Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.