Hovering TextButton, Or Image Label Cursor Solution - Tutorial

Hello developers!, i wanted to make a tutorial on how to fix the problem that when you change the mouse Icon using:

mouse.Icon = "rbxassetid//:00000000"

when you hover over a gui button our mouse icon that we stated above changes instantly to default, i have a simple solution to keep this clear and minimal:

First things first we use our chosen cursor and then we just add it with custom size and aswelll as an image label

Second step would be add a local script into the cursor that we have prior to this step as an imagelabel

Third Step

we move on writing some code! Exciting right?

-- state the runservice variable to start the code
local runservice = game:GetService("RunService")

then we add other variable that gets the player mouse so we can disable the default thing

local mouse = game.players.localplayer:GetMouse()

okay so 2 lines of code are going to be crucial with the next line

game:GetService("UserInputService").MouseIconEnabled = false

excellent!, these 3 lines of code will make future on our thing so lets just move ahead and add a simple function to change the mouse and get the mouse position andd replacing the disabled thing with our imagelabel (the imagelabel always has to be visible tho).

      script.parent.position = UDim2.new(0,mouse.X,0,mouse.Y)

now having our entire thing it would be something like this:

local RunService = game:GetService("RunService")
local mouse = game.Players.LocalPlayer:GetMouse()

 game:GetService("UserInputService").MouseIconEnabled = false

  script.Parent.Position = UDim2.new(0,mouse.X,0,mouse.Y)

Remember that the hierarchy of the stuff should be something like:

Alright, i hope this tutorial worked for most of you guys, any problem or stuff make sure to hit my dms and i will be up to helping you guys!, see ya!, if you guys want more tutorials and stuff ill make sure to add them for this epic community!!, Cheers!!

  • Karmak/Programmer

this is a life saver for me since I am coding something similar to this, very helpful resource thank you!

also by the way what does MouseIconEnabled do?

1 Like

It makes the main mouse invisible.

Just so you know, UserInputService has a single event which can handle all of this:

local UserInputService = game:GetService("UserInputService")
local Cursor = script.Parent

-- Remove the cursor icon
UserInputService.MouseIconEnabled = false

-- Listen for user input changes
    -- Determine if user input is mouse movement
    if input.UserInputType == Enum.UserInputType.MouseMovement then
        -- Get the current position of the cursor
        local position = input.Position

        -- Translate the cursor position into a UDim2 for the cursor image
        Cursor.Position = UDim2.fromOffset(position.X, position.Y)
1 Like

i wanted to keep it more short but to the point thanks eitherway

no problem!, im glad it helped you on your game or project development :), cheers!

1 Like