You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
When I hover over my part inside of a model I’d like to to be highlighted.
What is the issue?
When I hover over my part inside of a model it does not highlight.
What solutions have you tried so far?
I’ve looked on the DevForums & I’ve even used ChatGPT, but I’m stumped on this, and I really feel like its a simple scripting mistake…
Script that ChatGPT made that I’m currently using.
-- Services
local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
-- Define the tag to look for
local tagName = "Highlight"
-- Function to highlight parts (and parts within models)
local function highlightPart(part)
-- Check if the part already has a highlight object, to avoid duplicates
if not part:FindFirstChild("HighlightEffect") then
-- Create a Highlight instance
local highlight = Instance.new("Highlight")
highlight.Name = "HighlightEffect"
highlight.Parent = part
-- Optionally, you can add customization here, like changing the color
highlight.FillColor = Color3.new(1, 1, 0) -- Yellow fill
highlight.OutlineColor = Color3.new(1, 1, 0) -- Yellow outline
end
end
-- Function to process all parts inside a model (or model-like object)
local function processModelOrPart(object)
if object:IsA("Model") then
-- If it's a model, loop through all its parts
for _, descendant in pairs(object:GetDescendants()) do
if descendant:IsA("BasePart") then
highlightPart(descendant)
end
end
elseif object:IsA("BasePart") then
-- If it's a part directly, just highlight it
highlightPart(object)
end
end
-- Function to remove highlight from a part or model
local function removeHighlightFromModelOrPart(object)
if object:IsA("Model") then
for _, descendant in pairs(object:GetDescendants()) do
if descendant:IsA("BasePart") then
local highlight = descendant:FindFirstChild("HighlightEffect")
if highlight then
highlight:Destroy()
end
end
end
elseif object:IsA("BasePart") then
local highlight = object:FindFirstChild("HighlightEffect")
if highlight then
highlight:Destroy()
end
end
end
-- Function to add highlight to tagged models or parts
local function onTagAdded(object)
processModelOrPart(object)
end
-- Function to remove highlight when the tag is removed
local function onTagRemoved(object)
removeHighlightFromModelOrPart(object)
end
-- Highlight all currently tagged parts or models when the game starts
for _, object in pairs(CollectionService:GetTagged(tagName)) do
processModelOrPart(object)
end
-- Connect events to respond to tag changes dynamically
CollectionService:GetInstanceAddedSignal(tagName):Connect(onTagAdded)
CollectionService:GetInstanceRemovedSignal(tagName):Connect(onTagRemoved)
I’ve added tags to the correct items, and they are inside of a vehicle, which is inside of multiple models, maybe this is the issue?? I’m pretty stumped…
Your script works for me perfectly. What could be the issue is that there’s a limit of how many objects can be highlighted at once. Maybe you’ve reached that? If I recall correctly, it’s around ~30?
Also, within the video you showed us that the parts are in a collison group called “Highlight”, can you confirm if the parts actually have the “Highlight” tag?
The mouse has nothing to do with it, your script automatically highlights everything tagged whether or not the mouse is looking at it. I don’t know what’s wrong with your firetruck as the script works for me and it’s properly tagged, I’d recommend getting a scripter to look at it personally in studio, and if they can’t manage to get it to work, having them rewrite it as sometimes chat gpt does very stupid things when generating code.
when in doubt do some print debugging it always works when Im facing a problem that I feel completely stumped on. Through print debugging you can better theorize the problem, this is what chat gpt would also recommend but i would also recommend to try to rely on chat gpt less
I was wrong, its the actual script, and where the part is located. (I guess I wasn’t clear enough with ChatGPT because I wanted it to be highlighted when the mouse hovers over the part, guess it didnt get that.)
This script actually works perfectly fine, like I said its where the part is located, sense the part is inside of SIX different models, the script for some reason isn’t picking that up. You can see here on the left that I have one part that is open in the Workspace and another that is grouped (one time.) If I group this part again, the highlight will remove.
Edit: You have to actually hover over the part for it to highlight unlike chatGPT’s script where it auto highlighted
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Tag = "Highlight" --Change this to your tag
local function CheckForParts()
local Target = Mouse.Target
if Target and Target:HasTag(Tag) and not Target:GetAttribute("Highlighted") then
Target:SetAttribute("Highlighted", true)
local NewHighlight = Instance.new("Highlight")
NewHighlight.Parent = Target
end
end
Mouse.Move:Connect(CheckForParts)