This is happening because you are trying to connect the MouseClick event of the click detector to a function that you define after the connection. Therefore it appears as nil when you try to connect the event. To fix this, connect the event after you have defined the function.
The next problem is that you are trying to concatenate the player object on line 4, which is impossible. To fix this you must index the object's Name property, a string, which can be concatenated.
Additionally, You are incorrectly referencing the player on line 5. The MouseClick event of the click detector returns the player that clicked it, and you can simply index their PlayerGui directly from the player object that is passed into the function.
As a side note: players are not direct members of the game. They are members of the Players service, and therefore the way you would reference a player is not game[Player.Name], it is game.Players[player.Name].
As Isaque232 points out, you can not access the contents of the player's PlayerGui from the server, and instead you will have to use a RemoteEvent to send a message to the client so that they can make the Gui visible.
Revised Server Script:
local Remote = script.Parent:WaitForChild("RemoteEvent")
function onClicked(player)
print(player.Name.."Opened the admin panel")
Remote:FireClient(player);
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)
In a local script:
local Remote = workspace.somepart:WaitForChild("RemoteEvent")
local Player = game.Players.LocalPlayer;
function makeVisible()
Player.PlayerGui.Admin.Frame.Visible = true;
end
Remote.OnClientEvent:Connect(makeVisible);
2 comments
Thanks for your help everyone! Never been in a better comunity :)
Don't forget to accept the answer you found most helpful!