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)