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 appear when clicking a certain brick?

Asked by 7 years ago

I'm having a lot of trouble trying to get a character select screen to pop up. What lines of code can make it appear when a player clicks a button? This is what i have right now, any particular reason this code doesn't work?

local gui = game.StarterGui.CharSelect.CharSBox1

function onClicked(playerWhoClicked)
    gui.Visible = true
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

sorry if it looks really simple, i just started scripting not so long ago Any help appreciated :)

2 answers

Log in to vote
0
Answered by
Wiscript 622 Moderation Voter
7 years ago

This is a simple script and simple to be fixed. First of all, I'm guessing you want the script to appear for the player who clicked the brick. So, what you want to do is instead of going to the startergui and making the gui visible (which is useless for everyone), you want to access the player's "PlayerGui". That will enable the gui that was inserted in the player gui when the game started.

I'm giving you the script because you're a beginner and might not know still how to fix it. Here it is

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    Player.PlayerGui.CharSelect.Enabled = true -- Replace NAMEOFGUIHERE for the name of your GUI
end)

If it is a frame that you're trying to activate, then use this one

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    Player.PlayerGui.CharSelect.CharSBox1.Enabled = true
end)

If I helped you and this worked, please accept my answer. Thanks

Ad
Log in to vote
0
Answered by 7 years ago

In your code it looks like you're trying to change the GUI in StarterGui, this doesn't update the GUIs locally, it would just update the server master copy. If you were to reset or join the game after the click, the GUI would appear. Now onto my answer.

Instead of changing the server copy like you do, we need the Player Object to access it's GUI. We accomplish this by taking it from the prebuilt argument of the ClickDetector.

script.Parent.ClickDetector.MouseClick:connect(function(Player)

end)

This allows the Player Object to be referenced.

Next we want to find the PlayerGUI Object, this is where GUIs are copied to when a player joins a game.

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    local PlayerGui = Player.PlayerGui
end)

Next we just need to make the Gui Visible

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    local PlayerGui = Player.PlayerGui
    PlayerGui.CharSelect.CharSBox1.Visible = true
end)

Hope this helped! :)

Answer this question