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

I'm trying to create a button that opens up a GUI but it doesn't work, why?

Asked by 5 years ago

So basically when you click a button it will make these 2 GUIs appear. This is the code I put in the button but it doesn't work:

kickgui1 = game.StarterGui.GUIKick.Frameholder
warngui1 = game.StarterGui.GUIWarn.Frameholder

function onClicked(GUI)
    if kickgui1.Visible == false then
        kickgui1.Visible = true
        warngui1.Visible = true
    else
        warngui1.Visible = false 
        kickgui1.Visible = false
    end
end
script.Parent.MouseButton1Click:connect(onClicked)

2 answers

Log in to vote
0
Answered by 5 years ago

well, you have to use the player gui as the player gui is local to the player, which the starter gui isn't. I.E.

local plr = game.Player.LocalPlayer
kickgui1 = plr:WaitForChild("PlayerGui").GUIKick.Frameholder
warngui1 = plr:WaitForChild("PlayerGui").GUIWarn.Frameholder

function onClicked(GUI)
    if kickgui1.Visible == false then
        kickgui1.Visible = true
        warngui1.Visible = true
    else
        warngui1.Visible = false 
        kickgui1.Visible = false
    end
end
script.Parent.MouseButton1Click:Connect(onClicked)

while the starter gui is a child of the game object, the player gui is a child of the player object

0
It still didn't work. TypicallyPacific 61 — 5y
0
well, what is script.Parent theking48989987 2147 — 5y
0
The script's parent is TextButton. TypicallyPacific 61 — 5y
0
I fixed it. Thanks for the help anyways. TypicallyPacific 61 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I figured out how to fix it:

button = script.Parent
window = button.Parent
kickgui1 = window.Parent.Parent.GUIKick:FindFirstChild("Frameholder")
warngui1 = window.Parent.Parent.GUIWarn:FindFirstChild("Frameholder")

function onClicked(GUI)
    if kickgui1.Visible == false then
        kickgui1.Visible = true
        warngui1.Visible = true
    else
        warngui1.Visible = false 
        kickgui1.Visible = false
    end
end
script.Parent.MouseButton1Click:Connect(onClicked)

Answer this question