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

Attempt to index nil with 'FindFirstChild'?

Asked by 3 years ago

I'm making a zombie game with food and thirst systems. What I'm doing now is making so that the value of one's hunger or thirst is equal to the text of the GUI.

local plr = game.Players.LocalPlayer

while true do
    local systems = plr.Character:FindFirstChild("FoodAndThirstSystems")
    local thirstval = systems:FindFirstChild("ThirstVal")
    script.Parent.Text = "Hunger: " ..(tostring(thirstval.Value))
    if thirstval.Value < 10 then
        script.Parent.BackgroundColor3 = Color3.new(0.666667, 0, 0)
    else 
        script.Parent.BackgroundColor3 = Color3.new(0.333333, 1, 1)
    end
    wait(.1)
end

I have the part where the text of the GUI is equal to the Value of one's thirst value.

But in line 5, it has an error that always says " Attempt to index nil with 'FindFirstChild' " I've tried doing "systems.ThirstVal" but it still shows up with: Attepmt to index nil with 'ThirstVal'.

Please tell me what to do. Thanks!

1 answer

Log in to vote
0
Answered by 3 years ago

Welp nvm i just made it work.

0
what did you do? you should post how to fix it in the answer sections whether you or someone else found it WeaponisedPenguins 97 — 3y
Ad

Answer this question