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

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

Asked by
Anubizx 76
5 years ago
Edited 5 years ago

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
0
I tried to use Player but keep getting the same error Anubizx 76 — 5y
0
Data persistence is deprecated. Use DataStoreService. User#19524 175 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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

if v.Character and game.Players.LocalPlayer:WaitForChild("Ready").Value== true -- line 3
0
Why the WaitForChild? That doesn't fix the problem at all. User#19524 175 — 5y
0
Nope, it don't fixed the eror ;3! And it's in a script at ServerScriptService Anubizx 76 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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".)

Answer this question