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)
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.
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.