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

attempt to index nil with 'Value' please help?

Asked by 2 years ago

so i am making a natural selection simulation where animals would eat food and fight to survive basically. I have it so that plants can make seeds and i made it so that some seeds would be edible and some wont. My issue is in the seeds that are edible. whenever the seed gets touched by an animal, it says ( Workspace.Seeds.SeedToDuplicate.SeedIsEaten:7: attempt to index nil with 'Value' ) this is the script that is geting the error.

--script is in the seed
local seed = script.Parent
seed.Touched:Connect(function(hit)
    if hit.Parent.Parent == workspace.Population and seed:FindFirstChild("Edible").Value == true then
        local nutrients = seed:FindFirstChild("Nutrients")
        local animal = hit.Parent
        local energy = animal:FindFirstChild("Energy")
        energy.Value = energy.Value + nutrients.Value --ERROR IS IN THIS LINE
        seed:Destroy()
    end
end)

I have absolutely no idea why it would give that error and I dont know how I would fix it so any ideas would really help thanks

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago

either energy or nutrients does not exist please check if they exist

0
ohhhhhh omg lol i feel so dumb thank you, turns out the nutrients did not exist. I must have gotten confused because the plants have nutrients and i must have mistaken the plant for a seed. Thank you so much haha Afterineta 4 — 2y
0
np lol Puppynniko 1059 — 2y
Ad

Answer this question