Problem with Player Highlighting

Hello Devs,

I have a Player Oultine script and how it functions is when a player is behind a wall or basically when something obstructs the players camera then an outline of all the other players is displayed.

this is all in a local script in the StarterCharacterScripts using run service and raycasting.

But I have this problem where as in a player is obstructing another player it triggers the player outline so i want to ignore the other players or NPC.

below is the visualization of what i am facing

below is my script

local RS = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local char = plr.Character

RS.RenderStepped:Connect(function()
	local viewmodel = game.Workspace.Camera:GetChildren()
	local plrHead = char:FindFirstChild("Head")

	for i, v in pairs(game.Workspace:GetChildren()) do
		local human = v:FindFirstChild("Humanoid")
		local rootPart = v:FindFirstChild("HumanoidRootPart")

		
		
		if human and rootPart then
			local params = RaycastParams.new()
			params.FilterType = Enum.RaycastFilterType.Blacklist
			params.FilterDescendantsInstances = {viewmodel, char, v }
			local result = workspace:Raycast(plrHead.Position, rootPart.Position-plrHead.Position, params) 

			if not result then 
				local oldHighlight = v:FindFirstChild("Highlight")
				if oldHighlight then
					oldHighlight:Destroy()
				end
			else 
				local highlight = v:FindFirstChild("Highlight")
				if not highlight then
					local newHighlight = Instance.new("Highlight")
					newHighlight.Parent = rootPart.Parent
					newHighlight.FillTransparency = 1
					newHighlight.OutlineColor = Color3.fromRGB(8, 0, 255)
				end
			end
		end
	end
end)


any help is appreciated.

You can simply add the players and NPCs to your params.FilterDescendantsInstances.

Like so:

local NPCPath = PathToYourNPCs

local filterInstances = {
   viewmodel, 
   char, 
   v,
}

for _, npc in ipairs(NPCPath:GetChildren()) do
   table.insert(filterInstances, npc)
end

for _, player in ipairs(game.Players:GetPlayers()) do
   table.insert(filterInstances, player.Character)
end

params.FilterDescendantsInstances = filterInstances
1 Like

thanks this help solve the player obstructing problem very much

1 Like

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