New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 3 months 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 — 3mo

3 answers

Log in to vote
0
Answered by 3 months 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 — 3mo
Ad
Log in to vote
1
Answered by
thebayou 416 Moderation Voter
3 months 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 — 3mo
0
Not shows me Gui WolfNoobkiller6874 2 — 3mo
Log in to vote
0
Answered by 3 months ago

Execute in LocalScript.

0
How? WolfNoobkiller6874 2 — 3mo

Answer this question