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

attempt to index field 'LocalPlayer' (a nil value)?

Asked by 5 years ago

Here is code

wait (10)
local dil = game.Players.LocalPlayer.Backpack.Stats.Dil.Value
if dil == "ES" then
    GUI = game.ReplicatedStorage.SehireES
else
    if dil == "EN" then
        GUI = game.ReplicatedStorage.SehireEN
    else
        GUI = game.ReplicatedStorage.Sehire
    end
end

Play = game.Players
script.Parent.Touched:connect(function (hit)
if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
Play = game.Players[hit.Parent.Name]
if Play:FindFirstChild("PlayerGui") and not Play.PlayerGui:FindFirstChild(GUI.Name) then
GUI:Clone().Parent = Play.PlayerGui
end
end
end)

it needs to work but this script is not working

1
change connect to Connect, alo fix the indentation cause it looks like vomit, and change the "Play" to a local variable LoganboyInCO 150 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago

game.Players.LocalPlayer can only be used within a local script.

I belive you are trying to run this in a server script.

Since you are working with GUI's, you can put a "Local Script" not "Script" in StarterGui folder seen in the explorer tab in studio.

Then paste your code in the local script.

0
Thanks That worked WolfNoobkiller6874 2 — 5y
Ad
Log in to vote
1
Answered by
thebayou 441 Moderation Voter
5 years ago

You can only index LocalPlayer if the script is a localscript. On normal scripts, the server doesn't know what LocalPlayer is, so it's impossible to access.

0
ill try WolfNoobkiller6874 2 — 5y
0
Not shows me Gui WolfNoobkiller6874 2 — 5y
Log in to vote
0
Answered by 5 years ago

Execute in LocalScript.

0
How? WolfNoobkiller6874 2 — 5y

Answer this question