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

How do i make a gui apear on button click?

Asked by 5 years ago
Edited 5 years ago

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

0
Reference the PlayerGUI, not the Starter. Ziffixture 6913 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

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

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

Answer this question