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

How can I make a gui imagebox show when this is toggled?

Asked by
iHavoc101 127
4 years ago

I have a gui where it can toggle a menu, but I can't figure out how to make it show if it is toggled. This is the code for the parent:

local button = script.Parent
local toggled = false

local function onButtonActivated()
    if toggled == false then
        button.Image = "rbxgameasset://Images/Dropdown-active"
        toggled = true
    else        
        button.Image = "rbxgameasset://Images/Dropdown-null"
        toggled = false
    end
end

button.Activated:Connect(onButtonActivated)
0
What is wrong here? this should work starmaq 1290 — 4y
0
I am asking how to make the child appear once toggled iHavoc101 127 — 4y
0
As long as it's in a local script, the images work, and you have the button correctly identified in your variable, it should work. The only thing I can recommend is using print functions everywhere to try to identify the problem. Sulu710 142 — 4y
0
ok thanks iHavoc101 127 — 4y

1 answer

Log in to vote
0
Answered by
Sulu710 142
4 years ago

I have an idea. Create two "ImageLabel" Gui's in the same spot, one being the toggled image and one the non-toggled image. Then create a third Gui, this one a "ImageButton" Gui, and make it the same size and position as the two Image Label Guis. The Image Button should have a higher zindex than the Image Labels. Also, make the Image Button totally transparent. Then change your function so it makes the "ImageTransparency" of the desired toggled state Gui 0, and the other 1, making it appear as if the image has been changed.

local button = script.Parent
local toggled = false
local ToggledImage = -- Gui for the toggled image
local NonToggledImage = -- Gui for the toggled image 

local function onButtonActivated()
    if toggled == false then
        ToggledImage.ImageTransparency = 0
        NonToggledImage.ImageTransparency = 1
        toggled = true
    else       
        NonToggledImage.ImageTransparency = 0
        ToggledImage.ImageTransparency = 1
        toggled = false
    end
end

button.Activated:Connect(onButtonActivated)
Ad

Answer this question