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 make a button that opens another gui, but it won't work. What am I doing wrong?

I'm a beginner to scripting and I'm trying to make a button that opens another gui when it's clicked on. It won't work and the output isn't telling me anything. What am I doing wrong?

Code:

local exitButton = script.Parent

local missionGui = game.StarterGui.missionGui

exitButton.MouseButton1Click:Connect(function()

	missionGui.ScrollingFrame.Visible = true
end)

I have also tried

local exitButton = script.Parent

local missionGui = game.StarterGui.missionGui

exitButton.MouseButton1Click:Connect(function()	

	missionGui.Enabled = true
end)

3 answers

Your miskate is game.StarterGui. I see you dont know what is the difference with PlayerGui and StarterGui. That's easy, StarterGui is the storage who duplique your UIs in the PlayerGui of the client that enter in the game.

So to modify the UI of a client you must access of her PlayerGui.

Use a LocalScript:

local PlayerService = game:GetService('Players') -- This is the folder that you can see on the explorer.

local Player = PlayerService.LocalPlayer -- LocaScript only
local PlayerGui = Player:WaitForChild('PlayerGui')

local exitButton = script.Parent

local missionGui = PlayerGui:WaitForChild('missionGui')

exitButton.MouseButton1Click:Connect(function() 
    missionGui.Enabled = true
end)

Hope this help, to more questions put below in commentaries.

Starergui does not effect players you would need to edit the gui in PlayerGui. If its a localscript it's easy

local player = game.Players.LocalPlayer
player.PlayerGui.missionGui.Enabled = true

In your case

local player = game.Players.LocalPlayer
local exitButton = script.Parent

local missionGui = player.PlayerGui.missionGui

exitButton.MouseButton1Click:Connect(function() 

    missionGui.Enabled = true
end)

MUST BE A LOCAL SCRIPT

1 comment

1

I'm new to this you should accept @NiniBlackJackQc's Answer it's better

local exitButton = script.Parent
local missionGui = exitButton.Parent.Parent:WaitForChild("missionGui")
 
exitButton.MouseButton1Click:Connect(function()
     missionGui.ScrollingFrame.Visible = true
end)

This is a bit more advanced, but it should work. I wrote it assuming that exitButton is in a gui, not a frame. It works because anything in StarterGui goes into a player's PlayerGui.

1 comment

0

The worst thing to do

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