i’m trying to highlight objects. it works when i’m using models, but when i;m using regular objects that are not models (i.e. BaseParts) it parents the highlight to the workspace?
local function debug_parent_info(obj: Instance)
local parent = obj.Parent
print(parent)
local highlight = Instance.new("Highlight")
if parent:IsA("Model") then
highlight.Parent = parent
else
highlight.Parent = obj
end
end
didn’t work. it still parents the highlight to the workspace.
function scan(target_item)
local current_time = tick()
local parent = target_item.Parent
if last_scan_times[target_item] and (current_time - last_scan_times[target_item] < scan_cooldown) then
print("Cooldown active for target_item")
return -- Exit the function without scanning
end
local position = target_item.Position
local _, onscreen = current_cam:WorldToViewportPoint(position)
if onscreen then
local region = {current_cam.CFrame.Position, position}
local obstructions = {}
if parent.ClassName == "Model" then
obstructions = current_cam:GetPartsObscuringTarget(region, {char, target_item.Parent, target_item})
else
obstructions = current_cam:GetPartsObscuringTarget(region, {char, target_item})
end
-- print("obstructions:", obstructions)
if #obstructions > 0 then
warn("the target is onscreen, but obstructed.")
else
local highlight = Instance.new("Highlight")
highlight.OutlineColor = Color3.fromRGB(255, 242, 144)
highlight.FillTransparency = 1
highlight.Parent = target_item.Parent or target_item
task.delay(3, function()
debris_service:AddItem(highlight, 0.01)
end)
end
else
warn("the position is not onscreen :(")
end
end
local function debug_parent_info(obj: Instance)
local parent = obj.Parent
print(parent)
local highlight = Instance.new("Highlight")
if parent:IsA("Model") and parent ~= workspace then
highlight.Parent = parent
else
highlight.Parent = obj
end
end
Did you mean you wanna highlight all the Instance that are the children (Not descendants) of game?
local function debug_parent_info(obj: Instance)
local parent = obj.Parent
print(parent)
local highlight = Instance.new("Highlight")
if parent:IsA("Instance") and parent.Parent == game then
highlight.Parent = parent
else
highlight.Parent = obj
end
end
Wait, I know your meaning (Sorry if misunderstanding), Did you mean you wanna find the object that is a Descandants of game? if yes then
local function debug_parent_info(obj: Instance)
local parent = obj.Parent
print(parent)
local highlight = Instance.new("Highlight")
if parent:IsA("Instance") then
highlight.Parent = parent
else
highlight.Parent = obj
end
end
Try instance instead of model (Sorry if misunderstanding)