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

How do i make a gui apear on button click?

im trying to make a gui apear upon a button click but it is not working here is the script

    script.Parent.ClickDetector.MouseClick:Connect(function(Clicked)
       game:WaitForChild("Players"):GetPlayerFromCharacter(Clicked)
      .PlayerGui.ScreenGui.Frame.Visible = true
end)

idk whats wrong with it but it is not working

edit: i think i should add more i am trying to make a click detector do this and the script is in the part with the click detector

1 comment

0

Reference the PlayerGUI, not the Starter.

2 answers

The problem is GetPlayerFromCharacter(Clicked). The MouseClick() event gives us the Player clicking the ClickDetector, not the Character. So we don't need that function.

You need to use a remote event for this, but the GetPlayerFromCharacter function isn't needed, and you don't need to do game:WaitForChild("Players").First insert a remote event somewhere that both, the client and the server can access (replicated storage would be good) and now you need a local script.The local script cannot be put inside workspace because local scripts in workspace do not run. Now in the local script do this

game.ReplicatedStorage:WaitForChild("Put the name of the remote event here"):OnClientEvent(function()
    game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true
end)

once you do that, inside the click detector script do this

game.ReplicatedStorage:WaitForChild("Put the name of the remote event here"):FireClient(Clicked)

You will always need a player parameter when doing FireClient so you can use Clicked because the player was passed in it

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