Mouse.Target issue

I’m trying to make it so that whenever the player hovers their mouse over a part it’s transparency changes from 0 to 0.5, and the opposite with the mouse leaving. The issue I’m running into is that when I hover my mouse over the part, it does change it’s transparency. However whenever I leave my mouse it doesn’t change it’s transparency.

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()


UIS.InputChanged:Connect(function(input)
	if mouse.Target then
		if mouse.Target:FindFirstChild("Label") then -- *the script is identifying the part that has to be changed*
			mouse.Target.Transparency = 0.5
		else
			mouse.Target.Transparency = 0
		end
	end
end)

image
image

It’s because the mouse.Target in your mouse.Target.Transparency = 0 is no longer the original object. Your mouse has moved to target something else so you’re actually making that new object’s Transparency = 0.

Try something like

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local prevTarget = nil

UIS.InputChanged:Connect(function(input)
	if mouse.Target then
		if mouse.Target:FindFirstChild("Label") then 
			mouse.Target.Transparency = 0.5
            prevTarget = mouse.Target
		elseif prevTarget then
			prevTarget.Transparency = 0
            prevTarget = nil
		end
	end
end)
1 Like

Hi, I found an issue. Sometimes the transparency change when I hover over multiple parts.

Are you saying some stay transparent if you move your mouse fast enough? Because its not possible to have more than 1 mouse.Target at a time.

I understand, and I actually got it sorted out. I used Mouse.Move, which seemed to fix my issue.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.