Part highlight on Mouse hover!

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Part highlight on Mouse hover

  2. What is the issue? When I move mouse, Parts are highliting, but the parts I already highlighted with the mouse don’t become unhighlighted(so Instead of only one part highlighted, I have highlighted also previous highlighted parts )

  3. What solutions have you tried so far? Hard to find something on the theme, so I ask u for a help

The highlight is script’s child, script is Local in StarterPlayerScripts folder.
Tags are created with free plugin “Tags editor”

----------------------------------------- Here is the code

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local CS = game:GetService("CollectionService")

Mouse.Move:Connect(function()
	
	script.Highlight.Adornee = nil
	
	if script.Highlight.Adornee == nil then
		if CS:HasTag(Mouse.Target, "Highlitable") then
			script.Highlight.Adornee = Mouse.Target
		end
	elseif script.Highlight.Adornee ~= nil then
		return
	end
	
end)

1 Like
local Player = game:GetService('Players').LocalPlayer
local Mouse = Player:GetMouse()

local CS = game:GetService('CollectionService')

local highlight = script.Parent

Mouse.Move:Connect(function()
	local target = Mouse.Target
	if target and CS:HasTag(target,'Highlitable') then
		highlight.Adornee = target
	else
		highlight.Adornee = nil
	end
	target = nil
end)
1 Like

Didn’t help still
I think u even didn’t change anything here)

1 Like

I don’t know why you’re getting the player as your using the mouse not the player and at no point did you use the player in the script
As far as I know you don’t need to make the mouse a variable. You just use enter and leave as such…

local part = script.Parent

part.MouseHoverEnter:Connect(function()
–Change part color to new color
end)

part.MouseHoverLeave:Connect(function()
– change part color to original color
end)

2 Likes

I believe you need to put a ClickDetector inside the part because the MouseHoverEnter and MouseHoverLeave events will only fire when the player’s mouse begins/stops hovering over the ClickDetector’s parent. You would need to reference the ClickDetector instead of the part itself:

local part = game.Workspace.Part
local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = part

ClickDetector.MouseHoverEnter:Connect(function(player)
--What happens when the mouse is hovering over the part
end)

ClickDetector.MouseHoverLeave:Connect(function(player)
--What happens when the mouse stops hovering over the part
end)

--the variable/parameter "player" is the player who is hovering over the part
3 Likes

I will try using this, then I’ll tell you.

1 Like

I kinda reworked it but it really helped. SO thanks you for helping)

1 Like

That is actually true also I forgot about that. OP should change to your post as Solution not mine.

1 Like
local Game = game
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()

local Highlight = Instance.new("Highlight")

local function OnRenderStep()
	Highlight.Adornee = Mouse.Target
	Highlight.Parent = Mouse.Target
end

RunService.RenderStepped:Connect(OnRenderStep)

Quite simple.

2 Likes

I want it to only highlight when the target is a tool.

I Edited @Forummer 's Code , this script checks if the target is a tool then highlight (i added the or because you might be hovering a part inside that tool)

local Game = game
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()

local Highlight = Instance.new("Highlight")

local function OnRenderStep()
	if Mouse.Target:IsA("Tool") or Mouse.Target.Parent:IsA("Tool") then
		Highlight.Adornee = Mouse.Target
	    Highlight.Parent = Mouse.Target
	end
end

RunService.RenderStepped:Connect(OnRenderStep)
2 Likes

What is the point of the variable Game?
Is it too hard to just write game instead?