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

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

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

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

4 comments

0

It still didn't work.

0

well, what is script.Parent

0

The script's parent is TextButton.

0

I fixed it. Thanks for the help anyways.

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)

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