You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Part highlight on Mouse hover
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 )
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)
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)
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)
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
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)
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)