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