Highlight not appearing on local script

I’m trying to make a local system that when a player approaches a tool it gets highlighted but i can’t get it to work.

This is my code.

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

local player = Players.LocalPlayer
local tool = script.Parent.Parent
local handle = tool:WaitForChild("Handle")
local highlight = tool:WaitForChild("Highlight")

local ACTIVATION_DISTANCE = 10

local function isToolEquipped()
	local parent = tool.Parent
	return parent and parent:IsA("Model") and parent:FindFirstChildOfClass("Humanoid") ~= nil
end

RunService.RenderStepped:Connect(function()
	if isToolEquipped() then
		highlight.Enabled = false
		return
	end

	if not player.Character then
		highlight.Enabled = false
		return
	end

	local root = player.Character:FindFirstChild("HumanoidRootPart")
	if not root then
		highlight.Enabled = false
		return
	end

	local dist = (root.Position - handle.Position).Magnitude
	highlight.Enabled = dist <= ACTIVATION_DISTANCE
end)

Is the highlight parent the handle? if not, try making the handle the parent of highlight


It’s the parented to the tool but it should still work

I’ve fixed my problem by inserting this local script into StarterPlayerScripts:

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

ProximityPromptService.PromptShown:Connect(function(proximityPrompt)
	local adornee = proximityPrompt:FindFirstAncestorWhichIsA("BasePart") or proximityPrompt.Parent

	if adornee then
		local highlight = Instance.new("Highlight")
		highlight.Name = "PromptHighlight"
		highlight.Adornee = adornee
		highlight.DepthMode = Enum.HighlightDepthMode.Occluded
		highlight.FillColor = Color3.fromRGB(230, 230, 230)
		highlight.FillTransparency = 0.75
		highlight.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")

		proximityPrompt.PromptHidden:Once(function()
			highlight:Destroy()
		end)
	end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.