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

Attempt to index nil with 'FindFirstChild' what's this?Line 3

So im quite new to scripting and I just got the part of FindFirstChild and I'm attempting to make a stat that combines all the numbers of the other 3 stats Blue,Red and White but it gives the error in the title can someone help?And if there is another way of achieving what I want I would like to know.Here is my code:

while wait() do
	local player = game.Players.LocalPlayer
	local estats = player:FindFirstChild("stats")
	local white estats:FindFirstChild("White")
	local red = estats:FindFirstChild("Red")
	local blue = estats:FindFirstChild("Blue")
	local all = estats:FindFirstChild("All")
	all.Value = blue.Value + red.Value + white.Value
end

6 comments

0

it says nil, and it says findfirst child, this means one of your lines is looking for a value that doesnt exist, or doesnt exist yet, try doing while true do, and just putting wait() as first line in loop, in case it executes code THEN waits

0

Create your locals outside(above) the while loop, leaving just the 'all.Value = ...' line inside it.

0

good suggestion

0

Thanks for all your suggestions sadly it still gives me the same error and I have tried all of the suggestions.

0

I buddy! Can you please create a new script and insert the following code: warn(game.Players.LocalPlayer:GetChildren()). If it prints an empty table, then Stats is not a member of Player.

0

Tried it,it's true nothing shows but if I go into my player manually after starting the game the stats folder does indeed show.Maybe it's that my script misses something.

1 answer

oh wait i think i see the problem, you forgot an equal sign i think in line 4 it says

local white estats:FindFirstChild("White")

it should be

local white = estats:FindFirstChild("White")

so i guess try this

wait()--i always do this at the start of code or making variables
local player = game.Players.LocalPlayer
    local estats = player:FindFirstChild("stats")
    local white = estats:FindFirstChild("White")
    local red = estats:FindFirstChild("Red")
    local blue = estats:FindFirstChild("Blue")
    local all = estats:FindFirstChild("All")

while true do
    
	wait()
all.Value = blue.Value + red.Value + white.Value

end

i hope this helps :3

1 comment

0

True thanks this has probably just fixed a future error yet I have the nil one but thanks!

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