Check If A Proximity Prompt Is Visible To The Player

Can A Proximity Prompt Trigger A Function When Visible? Or Can Someone Find A Different Solution…

Trying To Enable A Highlight When A Proximity Prompt Is Visible Locally

Wanted End Goal:

https://developer.roblox.com/en-us/api-reference/event/ProximityPrompt/PromptShown

You could bind a function that creates a highlight once this event is triggered

e.g:

ProximityPrompt.PromptShown:Connect(function()
	local highlight = Instance.new("Highlight")
	highlight.Parent = Part
end)

EDIT: You could also use ProximityPromptService so that you don’t have to go through each prompt individually

4 Likes

Thanks A lot. For Anybody Else Here’s The Script I Used

---{Services}---

local ProximityPromptService = game:GetService("ProximityPromptService")

---{Functions}---

ProximityPromptService.PromptShown:Connect(function(ProximityPrompt)

	if ProximityPrompt.Parent and ProximityPrompt.Parent:IsA("BasePart") then

		local Highlight = Instance.new("Highlight", ProximityPrompt.Parent); Highlight.FillColor = Color3.fromRGB(255, 255, 255); Highlight.FillTransparency = 1

	end

end)

ProximityPromptService.PromptHidden:Connect(function(ProximityPrompt)

	if ProximityPrompt.Parent and ProximityPrompt.Parent:FindFirstChildOfClass("Highlight") then

		local Highlight = ProximityPrompt.Parent:FindFirstChildOfClass("Highlight")

		Highlight:Destroy()

	end

end)
1 Like

You should move this outside of the PromptShown scope, because this causes your code to connect a new function to the PromptHidden event every single time a prompt is shown instead of once which could cause a memory leak

ProximityPromptService.PromptShown:Connect(function(ProximityPrompt)

	local Highlight = Instance.new("Highlight", ProximityPrompt.Parent); Highlight.FillColor = Color3.fromRGB(255, 255, 255); Highlight.FillTransparency = 1

end)

ProximityPromptService.PromptHidden:Connect(function(ProximityPrompt)
	local Highlight = ProximityPrompt:FindFirstChildOfClass("Highlight")
	Highlight:Destroy()
end)
1 Like

I have one question though.
Is there a way to detect when its not shown anymore?

Yep, basically the opposite of the solution

ProximityPrompt.PromptHidden:Connect(function()
	--whatever
end)

I found out it does not work for some reason