How to disable the visibility of the ProximityPrompt locally?

  1. What do you want to achieve?
    I’m trying to add 2 or more seats to my vehicle.
  2. What is the issue?
    The ProximityPrompts from other seats show up
    ProblemPrompt
10 Likes

I’ve figured out a way you could do it, you could make it so when you are Seated, it gets the part you were sitting on and finds the first model ancestor and assume that is the car model as an example, then you go through all the descendants of that model and if the child is a ProximityPrompt, disable it, otherwise do nothing, and then store the model of the car in a variable. And once you are not seated anymore, loop through the model again using the variable, enable all ProximityPrompts and set the variable to nil

I did something like that in a LocalScript in StarterCharacterScripts and it worked for me

local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local formersit

hum.Seated:Connect(function(seated, seatpart)
	if seated then
		local model = seatpart:FindFirstAncestorOfClass("Model")
		for _,v in pairs(model:GetDescendants()) do
			if v.ClassName ~= "ProximityPrompt" then continue end
			v.Enabled = false
		end
		formersit = model
	else
		for _,v in pairs(formersit:GetDescendants()) do
			if v.ClassName ~= "ProximityPrompt" then continue end
			v.Enabled = true
		end
		formersit = nil
	end
end)

Inheritance doesn’t matter in this case so it’s best to just reference the ClassName directly. This should hopefully work for your needs and doesn’t require you to change anything related to the car. With this method, any nearby Proximity prompts unrelated to the car will still display

You could make it even faster by instead using a table and inserting the proximityprompts found into the table, but the difference is small, depending on how many parts are in the car, so it’s simpler to just go through the model again, but if needed, I could guide you on how to do it with a table instead.

Tell me if something isn’t working how it’s supposed to and I’ll try to help

2 Likes

It’s working, but how do you make it disabled for other models that are irrelevant to the current model?

You just have to reference the workspace so it goes through all of workspace to disable all the proximityprompts, with that change, it can be simply turned into

local char = script.Parent
local hum = char:WaitForChild("Humanoid")

hum.Seated:Connect(function(seated, seatpart)
    local state = not seated
	for _,prompt in pairs(workspace:GetDescendants()) do
		if prompt.ClassName ~= "ProximityPrompt" then continue end
		prompt.Enabled = state
	end
end)

If you have loads of stuff in your workspace, it would be better to put the things that have prompts in them into a folder and loop through that instead

I put off making it first loop through the workspace to get every proximity prompt because you may add or remove things with proximityprompts

@THECOOLGENERATOR That’s almost exactly how I had shown him, but you’re using the Sit property instead of the first return of Seated, which is true or false depending on if you’re sitting or not. And that wont reenable the prompts after you get up

1 Like

Maybe this?

Hum.Seated:Connect(function()
if Hum.Sit == true then
for _, v in pairs(workspace:GetDescendants()) do
if v:IsA("ProximityPrompt") then
v.Enabled = false
end
end
end)

For some reason, when the player jumped off of the seat, the prompt showed up again.

What do you mean? All prompts should up again when they get off the seat

I meant… When the player got off of the seat while I’m sitting, the prompt showed up again

So if someone got off when you’re sitting, it enabled them again for you?

Yes, that’s what I’m trying to say.

Is there a way to fix this bug?

I think I’ve fixed it.

Make a RemoteEvent called TogglePrompts and put it in ReplicatedStorage, then, in a localscript located in StarterPlayerScripts/anywhere a localscript can run and put this code in it

game:GetService("ReplicatedStorage").TogglePrompts.OnClientEvent:Connect(function(state)
	for _,v in pairs(workspace:GetDescendants()) do
		if v.ClassName ~= "ProximityPrompt" then continue end
		v.Enabled = state
	end
end)

And make a regular script in ServerScriptService and put this code in

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:WaitForChild("Humanoid").Seated:Connect(function(state)
			game:GetSerivce("ReplicatedStorage").TogglePrompts:FireClient(plr,not state)
		end)
	end)
end)

It should work as I tested it out using a 2 player local server test and when I got off one of them, the prompts stayed disabled for the other person

2 Likes

Alright, idk which ones which and it gave me errors like “GetService is not a valid member of DataModel “Game Name”” and “OnClientEvent can only be used on the client

This code

game:GetService("ReplicatedStorage").TogglePrompts.OnClientEvent:Connect(function(state)
	for _,v in pairs(workspace:GetDescendants()) do
		if v.ClassName ~= "ProximityPrompt" then continue end
		v.Enabled = state
	end
end)

Should be in a localscript where it can be ran

And this

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:WaitForChild("Humanoid").Seated:Connect(function(state)
			game:GetService("ReplicatedStorage").TogglePrompts:FireClient(plr,not state)
		end)
	end)
end)

In a regualr script in ServerScriptService

I accidentally wrote GetService as GetSerivce on that so that’s probably why you got one of those errors

3 Likes

Unfortunately, the prompt showed up when the other player got off of the vehicle while I’m still sitting on it… I tried dragging the localscripts both in the StarterCharacterScripts folder and the StarterPlayerScripts folder, it didn’t work, and I took a closer look at the scripts, there weren’t any typos.

Did you remember to remove the former script that was having issues?

Yeah, I did. Also, I am really sorry for telling you that your lines of code didn’t work out of the blue.

1 Like

It’s fine honestly, but its’ weird how it’s not working for you but it worked for me. Are you sure you removed any scripts that would cause this, and if you’re testing in-game instead ofa local server in studio, did you remember to publish?

I tested it in a published game.

I think I found the problem, I had a script inside the model that also enables/disables the visibility of the prompt, would you mind telling me which lines I should remove?

seat:GetPropertyChangedSignal("Occupant"):Connect(function() 
	if seat.Occupant then
		proximityPromt.Enabled = false
	else
		proximityPromt.Enabled = true
	end
end)

proximityPromt.Triggered:Connect(function(player)
	seat:Sit(player.Character.Humanoid)
end)