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

Problems with LocalPlayer?

Asked by
OKRPLAY 25
8 years ago

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:

function onChatted(message, player)
    if message == "/registerplayer" and tableContains(admins, player.Name) then
        print("GUI opening")
        game.ServerStorage.registerPlayer:Clone().Parent = game.Players.LocalPlayer.PlayerGui
    end
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?

1 answer

Log in to vote
1
Answered by
iFlusters 355 Moderation Voter
8 years ago

game.Players.LocalPlayer only works in a LocalScript as it is aClient Sidescript 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.LocalPlayercan only be used in a LocalScript.

Also you defined player on Line1 so just do:

local ServerStorage = game:GetService("ServerStorage")

-- Function

print("GUI opening")
ServerStorage.registerPlayer:Clone().Parent = player.PlayerGui
Ad

Answer this question