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