Value not fitting requirements for code to run, even though they should

In the cars in my game there is an owner value, and I am trying to make it so if you are not the owner then you will be ejected. However, this is not working. I have modified my rough code to the code below. The jump code works, I have tested this, and no errors are coming from output. I seriously have no clue as to why this isn’t working, as it’s just checking if strings match. The script is inside the vehicle seat.

(btw the owner.value is “e”)

car = script.Parent.Parent
ds = script.Parent
ds.Changed:connect(function(property)
	if property == "Occupant" then
		if ds.Occupant ~= nil then
			print(ds.Occupant.Parent.Name)
			print(car.Owner.Value)
			if (not car.Owner.Value) == ds.Occupant.Parent.Name then
				print("b")
				task.wait()
				ds.Occupant.Sit = false
				ds.Occupant.Jump = true
				wait(.1)
				ds.Occupant.Jump = false
			end
		end
	end
end)

Help would be appreciated!

1 Like

Does the check (the 3 if statements) not work or does the actual kicking out part not work?
Also right away this:
(not car.Owner.Value) == ds.Occupant.Parent.Name
Is almost certainly wrong, the left side will always be false.

1 Like

I think you meant

if not (car.Owner.Value == ds.Occupant.Parent.Name) then

or

if car.Owner.Value ~= ds.Occupant.Parent.Name then
1 Like

the if statements. Kicking the player out works fine.

1 Like

not using parenthesis gives me warnings in studio. I have literally coded with not yesterday and it didn’t require this. Maybe a new update, idk

Your code worked tho, thanks

1 Like

it is because of how order of operations work in Lua. If you don’t use parentheses, the not operator applies to car.Owner.Value, not the equality test.

It will show a warning because it is a really common coding mistake.

not a == b is the same as (not a) == b

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