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

How to make a window go back and fourth between transparency's when clicked? [SOLVED]

Asked by 5 years ago
Edited 5 years ago

Hello, I've been trying to create a window that can switch between transparency's but can't figure out the switching between the transparency's part. Here the code I've been using;

local window = script.Parent.Parent
script.Parent.MouseClick:Connect(function()
if window.Transparency = 0.4
window.Transparency = 0
print("Transparency Set to 0!")
else
window.Transparency = 0.4
print("Transparency Set to 0.4!")
end
end)

Thanks for any help!

0
Do you have the windows transparency set to 0.4 before you test? And where is this script located? MegaManSam1 207 — 5y
0
I have the window's transparency at 0.4 before starting, and the script is inside a ClickDetector which is inside the part. Mrtrainhead3617 2 — 5y
0
Oh, you have your syntax wrong, line 3 should read, if window.Transparency == 0.4 then MegaManSam1 207 — 5y
0
Just tried that, didn't work. Mrtrainhead3617 2 — 5y
View all comments (3 more)
0
Are you getting any errors? MegaManSam1 207 — 5y
0
does you click even register? put a print statement inside for testing, maybe you are clicking on something else in front of it. If it is a GUI element set the ZIndex for "script.Parent" element to higher value  goreacraft 1 — 5y
0
As for errors, none. I've set a print for both and it only comes up with the second "Transparency Set to 0.4!" Message. Mrtrainhead3617 2 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

I'm not 100% why your script isn't working, but I noticed you use the transparency property of the window to check if it is in a certain state, it's safer to use a different variable for the state of the part to prevent your script from breaking, like this:

local window = script.Parent.Parent
local ClickDetector = script.Parent
local state = 1
ClickDetector.MouseClick:Connect(function()
    if state == 1 then
        state = 2
        window.Transparency = 0.4
    elseif state == 2 then
        state = 1
        window.Transparency = 0
    end
end)

Hope this helps!

0
This worked! Thanks! Mrtrainhead3617 2 — 5y
0
Glad to help. MegaManSam1 207 — 5y
Ad

Answer this question