--Get touch input

ButtonGui.TouchImage.InputBegan:Connect(function(InputObj)
	if InputObj.UserInputType == Enum.UserInputType.Touch then
		if AdornedSeat then
			EnterStart("Touch")
		end
	end
end)

ButtonGui.TouchImage.InputEnded:Connect(function(InputObj)
	if InputObj.UserInputType == Enum.UserInputType.Touch then
		EnterKeyDown = false
	end
end)

function DisplayPrompt(Part)
	AdornedSeat = Part
	ButtonGui.Adornee = Part
	ButtonGui.Parent = Player.PlayerGui
	ButtonGui.Enabled = true
end

function HidePrompt()
	AdornedSeat = nil
	ButtonGui.Adornee = nil
	ButtonGui.Parent = script
	ButtonGui.Enabled = false
end

while true do
	if HRP and Humanoid then
		if not Humanoid.Sit then
			local Closest = math.huge
			local ClosestSeat = nil
			for i,Seat in pairs(Seats) do
				local Dist = (HRP.Position - Seat.Position).magnitude
				if Dist < Closest and Dist < MaxDistance and not Seat:FindFirstChild("SeatWeld") then
					Closest = Dist
					ClosestSeat = Seat
				end
			end
			if ClosestSeat then
				DisplayPrompt(ClosestSeat)
			else
				HidePrompt()
			end
		else
			HidePrompt()
		end
	else
		HidePrompt()
	end
	wait(0.15)
end
