Issue with outlines

Does anyone know how i could replicate roblox’s selection outlines for my game? I though this would be pretty simple to accomplish with highlights but the results aren’t as great as i hoped (examples below).

Studio version:

My version:
(long part selected but selection outline hidden)


(camera has ben adjusted but only part of the long part’s selection is visible)

My code:

local mouse = game.Players.LocalPlayer:GetMouse()
local targetChanged = false
local target = nil
local selectedPart = nil

local selection = script.Selection
local selected = script.SelectionSelected

mouse.Button1Down:Connect(function()
	if mouse.Target ~= nil then
		selectedPart = mouse.Target
		selection.Parent = script
		selected.Parent = selectedPart
	else
		selectedPart = nil
		selected.Parent = script
	end
end)

while task.wait(.1) do
	if mouse.Target ~= target then
		targetChanged = true
	end
	
	if mouse.Target == selectedPart and selectedPart ~= nil then 
		target = mouse.Target
	end
	
	target = mouse.Target
	if targetChanged and target ~= nil then
		targetChanged = false
		selection.Parent = target
	elseif target == nil then
		selection.Parent = script
	end
end

(I’d prefer to keep using highlights since they look better and they’re set to always on top since that’s what helps me get the most desireable effect, pls let me know if you think this is impossible.)

you need to change the depthmode to Occluded

edit: mb this is wrong i think there is no fix for this

ive tried that and it works like suggested, but i dont like it highlights other related parts (like the spawn point here).

im just checking to see if there’s othe solutions but i doubt it :sob:

yeah i just realized it :sob:

I’m sorry. I do not understand what is wrong with the highlights. They look fine to me. What are you trying to get them to look like?

im trying to get my outlines to look like the ones in the studio picture consistently, but as you can hopefully see in the second picture the green ouline only highlights from the baseplate and up instead of the whole grey part

Have you considered switching to selection boxes? They might work better than highlights, but only on rectangles.

Yeah i have but since i planned to use the outline on more than recatangles i though highights would be better

Do you need for all the highlights to be the same color? And you could make the baseplate not able to be selected, just a few parts.

I dont belive there’s a fix for this. My suggestion is you use selection boxes / other adornments for simple shapes like parts, and use highlights for meshes or other complex shapes.