Kick player out of seat not working

Hi. I’m trying to make it so that if a player that doesn’t own the vehicle enters the driver seat then they get kicked but it doesn’t work.

Script:

local ownerValue = script.Parent.Parent.Parent.Parent.Owner
local seat = script.Parent

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	print("Property changed")
	if seat.Occupant and seat.Occupant.Name ~= ownerValue.Value then
		seat.Occupant.Jump = true
	end
end)

and the ownerValue is set manually so it’s not a problem with it being changed on the client side.
In fact it doesn’t even print the property changed"

Anyone can help?

1 Like

where is this script located? Is it a local or a server script? Also print the ownerValue and see what it returns. The value also has to be set on the server. Possibly a remote event can do that if you change it on the client.

1 Like

Hello. It’s a serverscript located inside the drivers seat : )
I’ll try printing the ownerValue to see what happens.

Explorer:
Ignore the 2nd owner value under the driveseat.
image

Print Result:
Intentionally put rasm123x instead of rasm123z.
image

1 Like

What script kicks the player out? Check owner right?

EDIT:

I think I know the problem, its on this line:

Your checking the occupants name, but the occupant is the humanoid, not the character, so to fix this, you can replace it with:

if seat.Occupant and seat.Occupant.Parent.Name ~= ownerValue.Value then

I also changed some bits up, because I was testing in studio, full code:

local ownerValue = "JAcoboiskaka1122"
local seat = script.Parent

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	print("Property changed")
	if seat.Occupant and seat.Occupant.Parent.Name ~= ownerValue then
		print("Occupant found")
		task.wait(0.1)
		seat.Occupant.Jump = true
	end
end)
1 Like

Yes.

asdjnashdbahsbdhajsdasdhbashdbahusdasd

Make sure the seat CanTouch = true.

Try something like this:

print("ownerValue =", ownerValue.Value)

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if not seat.Occupant then return end
	if seat.Occupant.Parent.Name ~= ownerValue.Value then
		task.wait(1)
		seat.Occupant.Sit = false
	end
end)

Note that seat.Occupant is a Humanoid.

Yay it works. Thank you : )
Idk if the task.wait is crucial but the car manages to start in time and then kicks u out so the car is just running.

Would it break the script to remove the wait?

1 Like

You can, but it won’t function properly, make the delay shorter, and you should be good, otherwise, the player jumps with the chair.

2 Likes

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