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

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

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 comment

1

change connect to Connect, alo fix the indentation cause it looks like vomit, and change the "Play" to a local variable

3 answers

✓ Accepted answer

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.

1 comment

0

Thanks That worked

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.

2 comments

0

ill try

0

Not shows me Gui

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