Why can't i disable my proximity prompt

I’m making a car and I’m trying to disable other prompts when player sits on a seat but it wont work.

this is my code:

Char.Humanoid.Seated:Connect(function(Active, SeatPart)
	if SeatPart == nil then
		if seat == nil then return end
		local Attachment = nil
		local height = -math.huge
		for i, v in ipairs(seat:GetChildren()) do
			if v.ClassName ~= "Attachment" then continue end
			if v.WorldPosition.Y <= height then continue end
			height = v.WorldPosition.Y
			Attachment = v
		end
		Char.PrimaryPart.CFrame = Attachment.WorldCFrame
		seat = nil
		return 
	end

	if SeatPart.Name ~= "Seat1" then return end
		seat = SeatPart
	SeatPart.Occupant.Changed:Connect(function()
		if SeatPart.Occupant == nil then
			SeatPart.Parent.Seat2.PassengerPromptPart.EnterPassengerSeatPrompt.Enabled = true
			SeatPart.Parent.Seat3.PassengerPromptPart.EnterPassengerSeatPrompt.Enabled = true
		else
			SeatPart.Parent.Seat2.PassengerPromptPart.EnterPassengerSeatPrompt.Enabled = false
			SeatPart.Parent.Seat3.PassengerPromptPart.EnterPassengerSeatPrompt.Enabled = false
		end
	end)
end)
2 Likes

Do you mean to connect the event handler for enabling and disabling inside an if statement, inside another event handler?

Shouldn’t it be connected once and for all, outside/before the if statement?

You can use ProximityPromptService.Enabled to disable all prompts than to manually script every prompt in the car.

Example script from Documentation:

-- Server Script 1
local ProximityPromptService = game:GetService("ProximityPromptService")
local enablePrompts = workspace.EnablePrompts -- BindableEvent

-- Connected to a BindableEvent that is fired by another script controlling game logic
enablePrompts.OnServerEvent:Connect(function(enabled)
	ProximityPromptService.Enabled = enabled
end)