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
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