I need help with cursors

I’m building a first person game that already has a custom cursor.

My issue is that whenever I hover my mouse over a ClickDetector, the Clicking Cursor Icon doesn’t show up.

Here’s how the script I use looks like:
local player = players.LocalPlayer
local m = player:GetMouse()
m.Icon = “http://www.roblox.com/asset/?id=569021388

Whenever I disable the custom cursor script, the default roblox cursor appears and I’m able to see the Clicking Cursor while hovering a ClickDetector.

So, is it possible to have a custom cursor and a custom Clicking Cursor at the same time?

3 Likes

ClickDetectors have a CursorIcon property you can set to an assetID

1 Like

Yeah you can do this, here is the framework

--assuming this is a local script based on your current code 
local player = game.Players.LocalPlayer
--renamed some of your variables for readability purposes
local mouse = player:GetMouse()
local mouseIcon = "http://www.roblox.com/asset/?id=569021388"

local clickDetector = --put your click detector here
local clickDetectorIcon = --put the link for the click detector image here

clickDetector.MouseHoverEnter:Connect(function(hoveringPlayer)
    if hoveringPlayer == player then
         mouse.Icon = clickDetectorIcon
    end
end)

clickDetector.MouseHoverLeave:Connect(function(hoveringPlayer)
    if hoveringPlayer == player then
         mouse.Icon = mouseIcon
    end
end)

3 Likes

I’m aware of that. But as I said, when using the script I have to change the in-game cursor (not the clickcursor), when hovering on the click the ClickDetector the Click Cursor (which is set to default) doesn’t show up.

Setting mouse.Icon forces an icon that can’t be overridden except by some CoreScripts which act on hover. Romeo’s solution should do the trick but you will have to tailor it to account for an arbitrary number of ClickDetectors.

1 Like

Thank you so much for writing me this script, but unfortunately it doesn’t work :frowning:

When I run the game, the custom main cursor (“569021388”) doesn’t show up. Instead it’s the normal roblox cursor.

There’s also another problem as well: my game has multiple click detectors, not just one.

Keep in mind that i’m not a scripter and I might have done something wrong. I’ve tested the script multiple times though and nothing bad showed up on the output.

1 Like

I’m not sure why the cursor is not showing up but you can just loop over all the click detectors in the workspace and apply the script, like this:

local clickableObjects = workspace.Folder:GetChildren() --what i recommend you do is put all the object that have a click detector in one folder it will make the iterating faster
--this assumes that all clickdetectors are parented to a part and named ClickDetector
for _,clickableObject in pairs(clickableObjects)do
     local clickDetector = clickableObject.ClickDetector
     clickDetector.MouseHoverEnter:Connect(function(hoveringPlayer)
         if hoveringPlayer == player then
            mouse.Icon = clickDetectorIcon
         end
     end)

     clickDetector.MouseHoverLeave:Connect(function(hoveringPlayer)
         if hoveringPlayer == player then
             mouse.Icon = mouseIcon
         end
      end)
end

and for the icon are you the owner of the icon?

1 Like

I think the easiest way to code this is to get the mouse target (the part the mouse is over), search for a ClickDetector and update the cursor image respectively. You should also connect this with Runservice.Heartbeat to ensure it will be accurate every frame.

your way is easier but is way more intensive because it is ran every hearbeat, I would recommend you do it my way, you only wanna connect a function to heartbeat only when it is absolutely necessary, in this scenario it can be easily avoided.

its not being tedious, its being organised, and furthermore computer specs do vary and most people play roblox on mobile, furthermore it is waste to run such a function continuously when it is not necessary, it is a waste of resources, your argument is not valid for using renderstepped.

Yes they do. If they don’t, that’s an error in your implementation. In addition to this, ClickDetectors and their respective events are not unreliable. They may not be suitable for a certain use case but they certainly aren’t unreliable.

No you don’t. CollectionService is one way of voiding hierarchical dependence.

1 Like