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

Attemp to index field "LocalPlayer" a nil value??

Hey, i'm trying to check if a player has Ready.Value == true but i got a error Attemp to index field "LocalPlayer" a nil value

Here is the code:

for i,v in ipairs(game.Players:GetPlayers()) do
		if v then
			if v.Character and game.Players.LocalPlayer.Ready.Value== true then --/Error
				local t=v.Character:FindFirstChild("HumanoidRootPart")
				local h=v.Character:FindFirstChild("Humanoid")
				if t~=nil and h~=nil then
					if h.Health>0 then
						t.Velocity = Vector3.new(0,0,0)
						v.Character:MoveTo((CFrame.new(-109,47,16.5)+Vector3.new((math.random()-.5)*40,0,(math.random()-.5)*40)).p)
						local st = Instance.new("StringValue")
						st.Name = "SurvivalTag"
						st.Value = lastDisaster.Name
						local st2 = Instance.new("StringValue")
						st2.Name = "MapName"
						st2.Value = ns.Name
						st2.Parent = st
						local st3 = Instance.new("IntValue")
						st3.Name = "ExposureTag"
						st3.Value = 0
						st3.Parent = st
						st.Parent = v.Character
						if v.DataReady then
							disasterscore = v:LoadNumber("Played"..lastDisaster.Name) or 0
							v:SaveNumber("Played"..lastDisaster.Name,disasterscore+1)

							mapscore=v:LoadNumber("Played"..ns.Name) or 0
							v:SaveNumber("Played"..ns.Name,mapscore+1)

							totalscore=v:LoadNumber("PlayedTotal") or 0
							v:SaveNumber("PlayedTotal",totalscore+1)
						end
					end
				end
			end
		end
	end

2 comments

0

I tried to use Player but keep getting the same error

0

Data persistence is deprecated. Use DataStoreService.

2 answers

This is in a LocalScript right? And if so, try changing

if v.Character and game.Players.LocalPlayer:WaitForChild("Ready").Value== true -- line 3

2 comments

0

Why the WaitForChild? That doesn't fix the problem at all.

0

Nope, it don't fixed the eror ;3! And it's in a script at ServerScriptService

LocalPlayer doesn't exist in server scripts. You already have the player object on that line in v, so there's no reason not to use it again. That line then reads:

if v.Character and v.Ready.Value then

(You almost never need == true since everything that isn't false or nil is already considered "true".)

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