So I’m currently working on a vehicle, and I used CFrame to teleport the character’s HRP out of the vehicle. But for some reason it causes the vehicle to glitch for a second, and I can’t find a way to fix it.
The video:
The localscript:
local character = script.Parent
local HRP = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
local CAS = game:GetService("ContextActionService")
local LeaveCar = "Leave Car"
local function teleportPlayerOut()
humanoid.Sit = false
HRP.CFrame = HRP.CFrame * CFrame.new(-10, 10, 0)
end
local function handleAction(actionName, inputState, inputObject)
if actionName == LeaveCar and inputState == Enum.UserInputState.Begin then
teleportPlayerOut()
end
end
local function onSeated(isSeated, seat)
if isSeated and seat:IsA("VehicleSeat") then
CAS:BindAction(LeaveCar, handleAction, false, Enum.KeyCode.F)
CAS:BindActionAtPriority("LockSeat", function()
return Enum.ContextActionResult.Sink
end, false, Enum.ContextActionPriority.High.Value, Enum.PlayerActions.CharacterJump)
else
CAS:UnbindAction(LeaveCar)
CAS:UnbindAction("LockSeat")
end
end
humanoid.Seated:Connect(onSeated)
Any help would be appreciated