Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to mention this? Scripting helpers wants a specific title.

local ScreenGui = Instance.new("ScreenGui")

ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui") How do you mention ScreenGui.Parent etc?

Error: Workspace.Gui to Lua 5:19: attempt to index field 'LocalPlayer' (a nil value)

5 comments

0

you cant get the LocalPlayer from a server script

0

@theking48989987 but i can with a localscript?

0

yes, because local scripts are clientside and LocalPlayer is clientsided

0

can localscripts fireserver:()?

0

I edited my answer? I dont know what else the problem occuring may be caused by

2 answers

You must have the script as a LocalScript, Which can throw the errors that you represented in your question.

In addition to this, a recommendation from me, set the LocalPlayer before the script so if you want to refer to it multiple times in the script its overall easier to do such.

-->> Insert a localscript into Server script service

local player = game.Players.LocalPlayer
local ScreenGui = Instance.new("ScreenGui", player.PlayerGui) -- Set the parent as the second paramater of the instance instantly parent it.

1 comment

0

nvm the thanks above, the script still didnt create a screengui

You need to call it from a localscript, which is in something like ReplicatedFirst. LocalPlayer is not replicated between server/client, so the server tries to find a player called LocalPlayer with the script line you put, whilst a localscript would target the client.

3 comments

1

literally i'm posting a comment of the post above with do you have to use localscript, i found you two that say that its localscript. thanks

1

This is a poor answer. First, you don't "call" LocalPlayer. Second, your sentence about ReplicatedFirst was irrelevant and made no sense. Finally, your explanation is not correct. The server doesn't try to find a player called LocalPlayer because the LocalPlayer property exists. The property is just nil for scripts running on the server, thus the error.

0

yeah i use random words, quiet

This discussion is preserved as it was. New answers, comments, and votes are closed.