How to hide ProximityPrompts locally

Hello, very simple to understand, i have a car that has 4 seats and when you enter all the proximityprompts hide so you can see it better and not accidentally sit in another seat, but i forgot that doing that on a regular script would hide all the proximityprompts for everyone, so no one could longer enter in the car unless the person exits the car, any ideas for hiding the proximity prompt only for the player sitting? aka locally?

ive tried this script on the startercharacterscripts, but i had this error

image

for _, seat in pairs(workspace.Vehicles:GetDescendants()) do
	if seat:IsA("Seat") or ("VehicleSeat") then
		seat:GetPropertyChangedSignal("Occupant"):Connect(function()
			if seat.Occupant then
				for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
					if proximityPrompt:IsA("ProximityPrompt") then
						proximityPrompt.Enabled = false
					end
				end
			else
				for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
					if proximityPrompt:IsA("ProximityPrompt") then
						proximityPrompt.Enabled = true
					end
				end
			end
		end)
	end
end

driver seat proximity prompt script (there is one inside each seat)

local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent

local fr_pp = seat.Parent.Body.Seat.SeatFR.ProximityPrompt
local rl_pp = seat.Parent.Body.Seat.SeatRL.ProximityPrompt
local rr_pp = seat.Parent.Body.Seat.SeatRR.ProximityPrompt

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		proximityPrompt.Enabled = false

	else
		proximityPrompt.Enabled = true

	end
end)

proximityPrompt.Triggered:Connect(function(player)
	if player.Character.Humanoid.Sit == false then
		seat:Sit(player.Character.Humanoid)
	end
end)

hierarchy

image

1 Like

The error is cause of how you set this up, it has to be

if seat:IsA("Seat") or seat:IsA("VehicleSeat") then

Anhd if you want to do it locally, then use localscripts

i said i used a localscript

charchar

and that fixed the error but its still disabling to everyone (im using localscripts)

Make a RemoteEvent and fire it to the client.

Make sure to verify who is sitting since the event is being made for every client, maybe you can probably do something like this

local player = game:GetService("Players").LocalPlayer

for _, seat in pairs(workspace.Vehicles:GetDescendants()) do
	if seat:IsA("Seat") or seat:IsA("VehicleSeat") then
		seat:GetPropertyChangedSignal("Occupant"):Connect(function()
			local humanoid = seat.Occupant
			if not player.Character or (humanoid and not humanoid:IsDescendantOf(player.Character) then
				return
			end		
			if seat.Occupant then
				for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
					if proximityPrompt:IsA("ProximityPrompt") then
						proximityPrompt.Enabled = false
					end
				end
			else
				for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
					if proximityPrompt:IsA("ProximityPrompt") then
						proximityPrompt.Enabled = true
					end
				end
			end
		end)
	end
end
2 Likes

Totally genius, finally its working!

The only issue I may say is that if anyone gets off a seat it may make every prompt visible again. So I think ytou’d have to make a variable to store the previous person who sat down and when there’s no occupant, reference that variable

yea just saw that im testing here with local server then i entered the vehicle with both players and i left with the passenger one, and the proximityprompts appeared again

Try this out?

local player = game:GetService("Players").LocalPlayer

local formerOccupant

for _, seat in pairs(workspace.Vehicles:GetDescendants()) do
	if seat:IsA("Seat") or seat:IsA("VehicleSeat") then
		seat:GetPropertyChangedSignal("Occupant"):Connect(function()
			local humanoid = seat.Occupant
			local playerHumanoid = humanoid or formerOccupant
			if not player.Character or (playerHumanoid and not playerHumanoid:IsDescendantOf(player.Character) then
				return
			end		
			if humanoid then
				for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
					if proximityPrompt:IsA("ProximityPrompt") then
						proximityPrompt.Enabled = false
					end
				end
				formerOccupant = humanoid
			else
				for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
					if proximityPrompt:IsA("ProximityPrompt") then
						proximityPrompt.Enabled = true
					end
				end
				formerOccupant = nil
			end
		end)
	end
end
1 Like

it didnt work, the proximityprompts still appearing when the other player gets up

some way to get if there is someone still sitting at any of the seats, and this person have the proximityprompts disabled

I think you may need to tweak some of the logic since I think I may’ve done a mistake somewhere.

I think what else you could do is to make the code server sided and use a remoteevent to toggle the prompts for that client only

i will try that, so i would make the script on the serverscriptservice, then 2 remoteevents to toggle on and off, and when the humanoid is sitting toggle it off and when not toggle it on?

You only need 1 remoteevent for toggling, but you just give it the state yourself, if you want to toggle the prompts to on, pass in true, else pass in false

wait making it a server script wouldnt make the player variable wont work?

Yes, but you can easily get it back via

local player = game:GetService("Players"):GetPlayerFromCharacter(seat.Occupant.Parent)

IF seat.Occupant is not nil cause this would error

im not so expert on remote events, by toggling it true or false, theres a function of remoteevent that does that?

No it’s an argument

Example

RemoteEvent.OnClientEvent:Connect(function(state)
   --Codee
end)

--And somewhere else in a server script

RemoteEvent:FireClient(player, true)

--State would be true when the event is fired

i came up with this

script

local storage = game:WaitForChild("ReplicatedStorage")
local event = storage:WaitForChild("ProximityPrompts")

local formerOccupant

local function ToggleOnOff()
	for _, seat in pairs(workspace.Vehicles:GetDescendants()) do
		if seat:IsA("Seat") or seat:IsA("VehicleSeat") then
			seat:GetPropertyChangedSignal("Occupant"):Connect(function()
				local player = game:GetService("Players"):GetPlayerFromCharacter(seat.Occupant.Parent)
				local humanoid = seat.Occupant
				local playerHumanoid = humanoid or formerOccupant
				if not player.Character or (playerHumanoid and not playerHumanoid:IsDescendantOf(player.Character)) then
					return
				end		
				if humanoid then
					for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
						if proximityPrompt:IsA("ProximityPrompt") then
							proximityPrompt.Enabled = false
						end
					end
					formerOccupant = humanoid
				else
					for _, proximityPrompt in pairs(workspace.Vehicles:GetDescendants()) do
						if proximityPrompt:IsA("ProximityPrompt") then
							proximityPrompt.Enabled = true
						end
					end
					formerOccupant = nil
				end
			end)
		end
	end
end

event.OnServerEvent:Connect(ToggleOnOff())

local script

local player = game:GetService("Players").LocalPlayer
local storage = game:WaitForChild("ReplicatedStorage")
local event = storage:WaitForChild("ProximityPrompts")

for _, seat in pairs(workspace.Vehicles:GetDescendants()) do
	if seat:IsA("Seat") or seat:IsA("VehicleSeat") then
		seat:GetPropertyChangedSignal("Occupant"):Connect(function()
			if seat.Occupant then
				event:FireClient(player, true)
			end
		end)
	end
end