Hello,
i make a command that opens a GUI. If you run the Command it copy the GUI into the PlayerGui Folder. It works in Studio, but not online! I use a normal Script and NOT a LocalScript. Here is my Code:
1 | function onChatted(message, player) |
2 | if message = = "/registerplayer" and tableContains(admins, player.Name) then |
3 | print ( "GUI opening" ) |
4 | game.ServerStorage.registerPlayer:Clone().Parent = game.Players.LocalPlayer.PlayerGui |
5 | end |
6 | end |
Can it be that LocalPlayer only works with a LocalScript? And if LocalPlayer only works in a LocalScript, what Code do i need to use in a normal Script?
game.Players.LocalPlayer
only works in a LocalScript as it is aClient Side
script basically there are two sides of a server. The Server and the Client, LocalScripts are usually put into Player's Backpacks, StarterGui's etc.
In short game.Players.LocalPlayer
can only be used in a LocalScript.
Also you defined player on Line1 so just do:
1 | local ServerStorage = game:GetService( "ServerStorage" ) |
2 |
3 | -- Function |
4 |
5 | print ( "GUI opening" ) |
6 | ServerStorage.registerPlayer:Clone().Parent = player.PlayerGui |