Well, to find out if the player activated the MouseHoverEnter function of any ClickDetector, he used GetDescendants, like this:
for _, All_objects in pairs (workspace:GetDescendants()) do
if All_objects:IsA("ClickDetector") then
All_objects.MouseHoverEnter:Connect(function()
print("function activated")
end)
end
end
But doing it this way consumed too much and slows down the game, so I want to do it differently but get the same result (but this time it is optimized)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse:GetPropertyChangedSignal("Target"):Connect(function()
local target = mouse.Target
if target:IsA("BasePart") then
if target:FindFirstChild("ClickDetector") then
--do code
end
end
end)
Thanks for trying to help you, but it doesn’t seem to work for me. I don’t change it, I just put the data I need to make it do what I want, but apparently it doesn’t work.
MOUSE:GetPropertyChangedSignal("Target"):Connect(function()
local target = MOUSE.Target
if target:IsA("BasePart") then
if target:FindFirstChild("ClickDetector") then
print("asdad")
if not MENU_DE_MAPA:FindFirstChild("Mapa") or not MENU_DE_MAPA:FindFirstChild("Mapa"):FindFirstChild("OpenOrNotOpen") and MENU_DE_MAPA.Mapa.OpenOrNotOpen.Value == false then return end
self.MouseIcon = true
else
if not MENU_DE_MAPA:FindFirstChild("Mapa") or not MENU_DE_MAPA:FindFirstChild("Mapa"):FindFirstChild("OpenOrNotOpen") and MENU_DE_MAPA.Mapa.OpenOrNotOpen.Value == false then return end
self.MouseIcon = false
end
end
end)
Yeah, for some reason GetPropertyChangedSignal/.Changed don’t fire for the “Target” property of the mouse object.
The following does work & I have tested.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
while task.wait() do
local target = mouse.Target
if target then
if target:IsA("BasePart") then
if target:FindFirstChild("ClickDetector") then
target.Color = Color3.new(0, 0, 0)
end
end
end
end