The question is above.
It feels like I am repeating the same thing three times, even though it is slightly different each time.
Here is my code:
if Seats.Name == "FR" or Seats.Name == "BR" or Seats.Name == "Middle" then
local RayOrigin = Seats.Parent.RightSide.Position
local RayDirection = Vector3.new(0, 0, -5)
local Raycastparams = RaycastParams.new()
Raycastparams.FilterDescendantsInstances = {Seats.Parent.RightSide}
Raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
local RaycastResult = workspace:Raycast(RayOrigin, RayDirection, Raycastparams)
if RaycastResult then
Player.Character.HumanoidRootPart.CFrame = Seats.Parent.TopSide.CFrame
else
Player.Character.HumanoidRootPart.CFrame = Seats.Parent.RightSide.CFrame
end
elseif Seats.Name == "BL" then
local RayOrigin = Seats.Parent.LeftSide.Position
local RayDirection = Vector3.new(0, 0, 5)
local Raycastparams = RaycastParams.new()
Raycastparams.FilterDescendantsInstances = {Seats.Parent.LeftSide}
Raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
local RaycastResult = workspace:Raycast(RayOrigin, RayDirection, Raycastparams)
if RaycastResult then
Player.Character.HumanoidRootPart.CFrame = Seats.Parent.TopSide.CFrame
else
Player.Character.HumanoidRootPart.CFrame = Seats.Parent.LeftSide.CFrame
end
elseif Seats.Name == "DriveSeat" then
local RayOrigin = Seats.Parent.Body.LeftSide.Position
local RayDirection = Vector3.new(0, 0, 5)
local Raycastparams = RaycastParams.new()
Raycastparams.FilterDescendantsInstances = {Seats.Parent.Body.LeftSide}
Raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
local RaycastResult = workspace:Raycast(RayOrigin, RayDirection, Raycastparams)
if RaycastResult then
Player.Character.HumanoidRootPart.CFrame = Seats.Parent.Body.TopSide.CFrame
else
Player.Character.HumanoidRootPart.CFrame = Seats.Parent.Body.LeftSide.CFrame
end
end