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
This is in a LocalScript right? And if so, try changing
if v.Character and game.Players.LocalPlayer:WaitForChild("Ready").Value== true -- line 3
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".)