Problem with FindFirstChildOfClass and WhichIsA

Hello, since i wasnt able to use proximityprompts, i tried to use billboard guis for enter vehicles, and i ended getting this script

local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")

local carEnterGui = replicatedStorage.CarEnterGui

local Character = players.LocalPlayer.Character

local closestVehicle, gui, currentSeat


Character.Humanoid.Died:Connect(function()
	if gui then
		gui.Destroy()
	end
	script.Disabled = true
end)


userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		if gui then
			gui.Parent:Sit(Character.Humanoid)
		end
	end
end)

Character.Humanoid.Seated:Connect(function(active, currentSeatPart)
	if active then 
		currentSeat = currentSeatPart
	else
		currentSeat = nil
	end
end)

local toogleGui = function(toogle)
	if gui then
		gui:Destroy()
		gui = nil
	end
	
	if toogle == true then 
		gui = carEnterGui:Clone()
		gui.Parent = closestVehicle:FindFirstChildOfClass("Seat")
	end
end

runService.RenderStepped:Connect(function()
	local maxDistance = 15
	local newClosestVehicle
	
	for _, vehicle in pairs(workspace.Vehicles:GetChildren()) do
		if (vehicle.DriveSeat.Position - Character.HumanoidRootPart.Position).magnitude <= maxDistance and not vehicle.DriveSeat.Occupant then 
			maxDistance = (vehicle.DriveSeat.Position - Character.HumanoidRootPart.Position).magnitude
			newClosestVehicle = vehicle
		end
	end
	closestVehicle = newClosestVehicle
	
	if closestVehicle and not currentSeat then
		toogleGui(true)
	else
		toogleGui(false)
	end
end)

basically how this works is this gets the nearest seat from you, and put the billboardgui there, but theres one problem, and i want for both vehicleseats and normal seats, i tried using β€œor” but only worked for the first findfirstchild, maybe its a pretty basic mistake im making but i dont really know, any help is appreciated

Because your looking for the DriveSeat instead do:

	for _, vehicle in pairs(workspace.Vehicles:GetChildren()) do
     if vehicle:IsA("VehicleSeat") or vehicle:IsA("Seat") then
		if (vehicle.Position - Character.HumanoidRootPart.Position).magnitude <= maxDistance and not vehicle.DriveSeat.Occupant then 
			maxDistance = (vehicle.Position - Character.HumanoidRootPart.Position).magnitude
			newClosestVehicle = vehicle
		end
	end
end
1 Like

well now the gui doesnt appear