Issue with press key to leave car

Hi, I’m trying to make some cars that use Proximity Prompt and UserInputService but i have a problem with leaving car. My script works but it makes baseplate slick and
causes the car to still play driving sound.

robloxapp-20220424-1601574.wmv (2.7 MB)

Here is the my script:

local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.E then
			local plr = game.Players.LocalPlayer
			local chr = plr.Character or plr.CharacterAdded:Wait()
			local hrp = chr:WaitForChild("HumanoidRootPart")
			if hrp then
				for i, v in pairs(hrp:GetJoints()) do
					if v.Name == "SeatWeld" then
						v:Destroy()		
					end
				end
				return
			end
		end
	end	
end)

Thanks.:slightly_smiling_face:

1 Like

i have a video that shows you how to make a car with a Proximity Prompt and where you can use the jump key to exit the car

but it does not have driving sounds but maybe it will be helpful

2 Likes

I’m assuming the issue is because the car sounds start to play when the VehicleSeat has an Occupant, and stop when there isn’t one. You are not able to change the Occupant property of a seat as it is view only, and only deleting the SeatWeld will not get rid of the occupant.

I don’t think this is the best solution, but one that I came up with instantly is making the player jump. This will not only destroy the SeatWeld, but also get rid of the Occupant of the VehicleSeat.
You can force the player to jump with :

Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)

Hope this helps you, and if it doesn’t/you have any issues with this solution let me know and I’ll try to come up with a new one :grin:

1 Like

Thanks, but i set jump power to 0 while driving.

This is off topic, but instead of setting the JumpPower to 0, I would recommend you to disable the player’s Jumping humanoid state. You can do that with the code below -

Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

And then continuing the main topic, even when the player’s JumpPower/Height is 0, when they are forced to jump it should still make them stop driving a car, even if they don’t actually jump.

If you do switch to disabling the state, I would recommend that you re-enable the state before forcing the player to jump.

1 Like

Thanks, i will try that solution.

No problem :smile:

If you experience any problems with the solution, let me know and I will try to respond as fast as possible.

1 Like