Hello! I’m trying to make a custom mouse icon that rotates when you can interact with a click detector. So I did that by leaving the original mouse icon invisible and creating two fake mouses using image labels, with one of them stopped and the other one spinning.
local normalMouse = script.Parent:WaitForChild('MouseSpinning').FakeMouse
local movingMouse = script.Parent:WaitForChild('MouseSpinning').FakeMouseMoving
But there’s a problem…
At first cd was a table with all the click detectors, but it wasn’t the best method since some click detectors would be added later, and it would be a mess to make all of them with a code that animates the “mouse icon”. So I tried this:
local cd = game.Workspace:GetDescendants()
for i, v in pairs(cd) do
if v:IsA("ClickDetector") then
normalMouse.ImageTransparency = 1
movingMouse.ImageTransparency = 0
normalMouse.ImageTransparency = 0
movingMouse.ImageTransparency = 1
But as you can imagine, it doesn’t work…
What could I do? (the camera is locked to first person, so the only problem here is to get all the click detectors, even if them are added later)
I would do this…
In a local script, have a loop, while do, or using render step, etc…
Each pass of that loop, get the instance the mouse is pointed at, and check if it has a click detector as its child
if yes, make your icon the spinning one,
if no, make your icon the non spinning one
keep a variable holding the last instance your mouse was over, and only do the check if the current instance the mouse is looking at is different than the last instance it was looking at
Here is what I used in my game, back when filtering enabled was new and click detectors were not working.
Put in a local script
GrabIcon = "rbxasset://textures/DragCursor.png"
local lastPart = nil
local function onRenderStep(deltaTime)
if Mouse.Target ~= lastPart then
local icon = ""
local tool = Player.Character:FindFirstChildOfClass("Tool")
if Mouse.Target and not tool and Mouse.Target:FindFirstChild("ClickDetector") then
icon = GrabIcon
lastPart = Mouse.Target
Mouse.Icon = icon