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

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

Asked by 4 years ago

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)

0
you cant get the LocalPlayer from a server script theking48989987 2147 — 4y
0
@theking48989987 but i can with a localscript? iiDkOffical 109 — 4y
0
yes, because local scripts are clientside and LocalPlayer is clientsided InfiniteYield 41 — 4y
0
can localscripts fireserver:()? iiDkOffical 109 — 4y
0
I edited my answer? I dont know what else the problem occuring may be caused by AltNature 169 — 4y

2 answers

Log in to vote
0
Answered by
AltNature 169
4 years ago
Edited 4 years ago

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.

0
nvm the thanks above, the script still didnt create a screengui iiDkOffical 109 — 4y
Ad
Log in to vote
-2
Answered by 4 years ago

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.

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 iiDkOffical 109 — 4y
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. User#26971 0 — 4y
0
yeah i use random words, quiet MachoPiggies 526 — 4y

Answer this question