Character gets flung when exiting seat

I have a wheelchair which players can sit on. This wheelchair is a tool that you can equip and move around. Someone else can use a ProximityPrompt to sit on it. But there’s a problem.

There is a VehicleSeat in the wheelchair and I use :Sit() to force the player into the seat. Later, they can jump out to leave the seat. But when they jump out, they get “flung” across the map.

Sometimes, they also jump really high, other times, it works just fine. In Studio it works great, but as soon as I join the real game, whenever you jump out of the seat, you get flung.

Here’s my seat exiting code:

seat.Changed:Connect(function()
	if seat.Occupant == nil then
		if playerSitting then
			local char = playerSitting.Character
			local hrp = char:FindFirstChild("HumanoidRootPart")
			local hum = char:FindFirstChild("Humanoid")

			hum.Sit = false
			
			game:GetService("RunService").Heartbeat:Wait()
			hrp.AssemblyLinearVelocity = Vector3.zero
		end
		prompt.Enabled = true
		playerSitting = nil
	end
end)

Any and all help is greatly appreciated. If you have any questions, don’t hesitate to ask.

have you tried turning off CanCollide for some parts of the wheelchair? Assuming the property is on?

3 Likes

Set the network ownership to the player when seated, and then back to auto when they exit the seat… this helps with the flinging.

1 Like

@Foxxive Yes, I’ve done that.

@RMofSBI Not sure how that would help.

What other scripts are in your wheelchair, do you have any weld scripts?

1 Like

Just that one script, which basically does this:

  1. When player triggers prompt
  2. Put them in the seat
  3. If they jump
  4. try to set their velocity to 0 so they dont fling

Is there any part of the script that parents the vehicle or vehicle seat to the player… this is what causes the fling, and when i removed this from my vehicle scripts they all stopped flinging.

Edit: does the player keep getting flung even when they try to go back to the seat?

The vehicle seat is parented to the wheelchair.

No, they only get flung once.

1 Like

So how do I fix this problem? @RMofSBI

To anyone who’s interested, I managed to solve this issue. Although it’s a bit hacky, it works perfectly fine for my purposes. Just use a RunService.Stepped loop that repeats around 20 times, in that loop set the HRP position to the seat’s position and set the HRP velocity to zero.

1 Like

Would anchoring the character’s root part for a frame when they leave the seat suffice? Would definitely be more performant.

1 Like

I tried that, it actually didn’t work. In fact, the whole wheelchair just broke.