Attempt to index nil with 'Value'

Hi, so I’m currently struggling to fix my script that spawns a car for you if you have enough money to buy a car. Here is a screenshot with the error message. If you need anything else, feel free to ask.

2 Likes

How do you expect to be helped without the code that is causing the problem. Could you post it please?

2 Likes

Sorry, I’ll post it now.

Here is the script

1 Like

I would say that FindFirstChild(script.Parent.CarSelected.Value) failed. Value is a property not a child of your CarSelected

1 Like

FindFirstChild does not return a boolean, it either returns the Instance that you’re trying to find or nil, so instead of doing == true you would instead either make sure that it is not nil or not compare it to anything, kind of like this

if game.Players.LocalPlayer:FindFirstChild(script.Parent.CarSelected.Value) ~= nil then
-- or you could do this as well
if game.Players.LocalPlayer:FindFirstChild(script.Parent.CarSelected.Value) then

For the main issue, re-check the contents of script.Parent and confirm that there is a CarSelected object in it

3 Likes

Change line 166 to:

if game.Players.LocalPlayer:FindFirstChild(script.Parent.CarSelected).Value == true then

Pretty sure that’s what you were trying to do.
As nuttela stated above, FindFirstChild returns an instance or nil.