How To Check If Something Exists

I want to check if NameCar exists or has the same name as CarName’s Value

if finder.CarName.Value == not plr.OwnCar.NameCar then

Error I keep getting (NameCar is not a valid member)

I am aware of other questions about this, but their solutions didn’t work when I tried them.

2 Likes

This is done with nil

if workspace.Sounds ~= nil then
	-- sounds is there
end

Maybe something like this …

if plr.OwnCar.NameCar ~= nil then
 -- NameCar is there
end
1 Like

What is OwnCar? An instancevalue?

1 Like

You can use :FindFirstChild

local value = workspace:FindFirstChild("Value")
if value then
    -- runs if the value exists
end

I think you also mentioned checking if the value of namecar is the same as carname

local nameCar = plr.OwnCar:FindFirstChild("NameCar")
if nameCar and nameCar.Value == finder.CarName.Value then
    -- name car exists and is equal to the value of carname
end
3 Likes

OwnCar is the folder in the player its being used for a datastore.

What you mean by instancevalue??

This didn’t work for me sadly.
I want to check if I already got a value named after the car the player has if not then I want to create a new value then

Is how you can check for an object without creating an error if it isn’t there.
error (NameCar is not a valid member)

if plr.OwnCar.NameCar ~= nil then
 -- NameCar is there
else
 -- NameCar is not there
end

Glad you got this … this wasn’t a code. This was an example of the ~= logic.

1 Like

I got it working by using your system
Thanks for your help!!

1 Like

Hi, I still keep getting that error

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.