Prompt Highlight Effect

How to easily highlight objects that have a proximity prompt!

by YasuYoshida

Author Avatar

This is the following heiarchy you'll need for the tutorial:

StarterPlayer ‎ ‎ ‎ StarterPlayerScripts ‎‎ ‎ ‎ ‎ ‎ ‎ LocalScript


Listening to PromptShown

Inside that local script, we'll be writing the code for this tutorial. To start, we need to listen to an event called PromptShown that's a part of ProximityPromptService. As you can tell, it's an event that fires whenever a prompt is shown.

local ProximityPromptService = game:GetService("ProximityPromptService")

ProximityPromptService.PromptShown:Connect(function(proximityPrompt)

end)

Creating the Highlight

Now, that we're listening to that event, we can create a new highlight instance. We'll want this highlight to be parented to the local player's PlayerGui and we'll want the adornee to be one of the following:

Knowning this, we can continue to add on to the script.

local ProximityPromptService = game:GetService("ProximityPromptService")
local Players = game:GetService("Players")

ProximityPromptService.PromptShown:Connect(function(proximityPrompt)
	local highlightAdornee = proximityPrompt:FindFirstAncestorWhichIsA("BasePart") or proximityPrompt:FindFirstAncestorWhichIsA("Model")

	local newHighlight = Instance.new("Highlight")
	newHighlight.DepthMode = Enum.HighlightDepthMode.Occluded
	newHighlight.FillColor = Color3.fromRGB(255, 255, 255)
	newHighlight.FillTransparency = 0.9
	newHighlight.OutlineColor = Color3.fromRGB(255, 255)
	newHighlight.OutlineTransparency = 0
	newHighlight.Adornee = highlightAdornee
	newHighlight.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")
end)

Destroying the Highlight

This is great! We now have a highlight appear on the object that has a proximity prompt that is showing. But we have a problem. That highlight won't go away once the prompt is hidden. We'll need to destroy the highlight when this happens.

To do this, we'll listen to the proximity prompt's PromptHidden event, but only once so we don't need to cleanup the connection.

local ProximityPromptService = game:GetService("ProximityPromptService")
local Players = game:GetService("Players")

ProximityPromptService.PromptShown:Connect(function(proximityPrompt)
	local highlightAdornee = proximityPrompt:FindFirstAncestorWhichIsA("BasePart") or proximityPrompt:FindFirstAncestorWhichIsA("Model")

	local newHighlight = Instance.new("Highlight")
	newHighlight.DepthMode = Enum.HighlightDepthMode.Occluded
	newHighlight.FillColor = Color3.fromRGB(255, 255, 255)
	newHighlight.FillTransparency = 0.9
	newHighlight.OutlineColor = Color3.fromRGB(255, 255)
	newHighlight.OutlineTransparency = 0
	newHighlight.Adornee = highlightAdornee
	newHighlight.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")

	proximityPrompt.PromptHidden:Once(function()
		newHighlight:Destroy()
	end)
end)

Conclusion

And there you have it! That's all the code that is necessary to do such a nice effect! The only caveat is that if you want to highlight a whole model, you'll need to parent the proximity prompt to a model that has a PrimaryPart assigned. If you don't assign one, the prompt won't be shown, which means the highlight won't be shown as well.

You can easily change the properties assigned to newHighlight to get the look you desire for your highlight. If you want an even more versatile version of this script, I have a free model script called Simple Prompt Highlight that has customization attributes!

View in-game to comment, award, and more!