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

attempt to index nil with 'Value' please help?

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

✓ Accepted answer

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

2 comments

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

0

np lol

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