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)
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)