So im working on a RTS (Real time strategy) game, and I want a highlight to appear over the rig when my mouse hovers over it. I have no ideas on how to do this, and no sources online helped me.
As it stands, this question seems to be asking to make the entire system. It would help if you could narrow down your question to one specific issue.
If you’re searching for something like “how to highlight object when being hovered” then you probably won’t get any results since that’s pretty specific. But if you make it more general, like “how to detect when part is being hovered” you can find results that can help you get started.
All you’d really need to do is detect when you’re hovering over a part like this would be to spawn a highlight in it, making sure to remove it when you stop hovering over the object.
Sorry, I worded the post incorrectly, I meant to ask for any tips/pointers to making this.
If that’s the case, check the link on my old reply. That’ll tell you if your mouse is hovering on something. Implement some sort of way to detect if the object is meant to be “highlightable” or not, like by checking for an attribute or something. Then create a highlight instance in it to make it highlighted visually. Finally, if you mouse off of the object (can be done by saving your last highlighted target and comparing it against the new one each frame), delete the highlight.
Bit of a word salad but that’s how I’d do it.
local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse:GetPropertyChangedSignal("Hit"):Connect(function()
local Target = Mouse.Target
if Target then
local Model = Target:FindFirstAncestorOfClass("Model")
if Model:GetAttribute("ValidTarget") then
local Highlight = Model:FindFirstChild("HoverHighlight")
if Highlight == nil then Highlight = Instance.new("Highlight") Highlight.Name = "HoverHighlight" end
Highlight.Parent = Model
--Do whatever u want
end
end
end)
^ This would work but does not account for mousing off of a target.
true,
local Mouse = game.Players.LocalPlayer:GetMouse()
local Highlight = Instance.new("Highlight")
Highlight.Name = "HoverHighlight"
Mouse:GetPropertyChangedSignal("Hit"):Connect(function()
local Target = Mouse.Target
if Target then
local Model = Target:FindFirstAncestorOfClass("Model")
if Model:GetAttribute("ValidTarget") == true then
if Highlight == nil then Highlight = Instance.new("Highlight") Highlight.Name = "HoverHighlight" end
Highlight.Parent = Model
--Do whatever u want
else
Highlight.Parent = game.ReplicatedStorage
end
else
Highlight.Parent = game.ReplicatedStorage
end
end)
if that doesn’t work, use this instead as another option
local Mouse = game.Players.LocalPlayer:GetMouse()
local Highlight = Instance.new("Highlight")
Highlight.Name = "HoverHighlight"
game:GetService("RunService").Heartbeat:Connect(function()
local Target = Mouse.Target
if Target then
local Model = Target:FindFirstAncestorOfClass("Model")
if Model == nil then return end
if Model:GetAttribute("ValidTarget") == true then
if Highlight == nil then Highlight = Instance.new("Highlight") Highlight.Name = "HoverHighlight" end
Highlight.Parent = Model
--Do whatever u want
else
Highlight.Parent = game.ReplicatedStorage
end
else
Highlight.Parent = game.ReplicatedStorage
end
end)