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

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

Asked by
Llorko 10
3 years ago
Edited 3 years ago

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

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 AlexanderYar 788 — 3y
0
Create your locals outside(above) the while loop, leaving just the 'all.Value = ...' line inside it. DinozCreates 1070 — 3y
0
good suggestion AlexanderYar 788 — 3y
0
Thanks for all your suggestions sadly it still gives me the same error and I have tried all of the suggestions. Llorko 10 — 3y
View all comments (2 more)
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. KingCh1ll 2 — 3y
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. Llorko 10 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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

0
True thanks this has probably just fixed a future error yet I have the nil one but thanks! Llorko 10 — 3y
Ad

Answer this question