Player not supposed to leave car

In my game, when a player enters a car, is not supposed to leave even if he jumps but sometimes players can leave by jumping when changing cars cframe or moving with a bodymover.

I think this mostly happens when user has low fps or high ping

VIDEO:

this is the script that trys to not let player get out of car

game:GetService("UserInputService").JumpRequest:Connect(function()
	
	
	if IsGrounded() then
		player.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
		
		if car.Chassis.Velocity.Y < 0 then
			
			car.Chassis.Velocity = Vector3.new(car.Chassis.Velocity.X, 0, car.Chassis.Velocity.Z)
		end
		
	car.Chassis.Velocity = car.Chassis.Velocity + Vector3.new(0,car.JumpForce.Value,0)
	end
	
	
end)

You should be able to just set the player’s jump power to 0 to stop them from getting out of the car seat

1 Like

You can try checking for the actual car seat being free instead, by checking for Seat.Occupant:

local Seat = car.Chassis --Path of your car Seat

local humanoid: Humanoid? = nil
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local occupant = Seat.Occupant
	if not occupant and humanoid then
		Seat:Sit(humanoid)
	elseif occupant and not humanoid then
		humanoid = occupant 
	end
end)

On top of this, you may also want to set the humanoid JumpPower property to 0 as suggested above. Otherwise, the humanoid will be able to jump like normal and the script will forcibly put it back on the seat.

1 Like

i tried, its not working, btw the script is on a local one, does it has anything to do with it? i will try on server script to make sure

alr i made some progress?

but is now too glitchy and stuff

nevermind, i reused the previous method before urs and i solved the problem thanks anyway

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