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

I'm trying to make a button that opens another gui, but it won't work. What am I doing wrong?

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
I'm new to this you should accept @NiniBlackJackQc's Answer it's better lukeh990 23 — 4y
Log in to vote
0
Answered by 4 years ago
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.

0
The worst thing to do NiniBlackJackQc 1562 — 4y

Answer this question