Custom Mouse Icon Module!

I’ve searched to make sure that this didn’t exist before I made it and I didn’t find anything so here you go:

I’ve made a module that makes it much easier to add custom mouse cursors! Hope you’ll find it useful

Custom Mouse API

Require the Module:
local m = require(script:WaitForChild("CustomMouse"))

Enable the mouse cursor:
m:StartUsingMouse(image id, size of cursor, gui)
Note: The arguments are not necessary, but it allows you to make it custom, if you add your own arguments. It has it’s own default arguments too. Also, make sure theres no “rbxassetid://” in the id, just the numbers!

Disable the mouse cursor:
m:StopUsingMouse()
Another note: This deletes the entire gui for the mouse, use this only if needed.

Use the API

To use the module, you can either get the model from here:

Or you can create a ModuleScript inside your localscript, and put this code inside if you’re not comfortable taking the model:

--[[
Code by infiniteRaymond!
Don't steal or ill be very saddo

Enjoy!
]]

local main = {}

local mouseActive = false
local CursorGui

function main:StartUsingMouse(ImageId, Size, Gui)
	-- Run some checks to make sure that we wont have 2 mouses and that its running on the client only
	if not game.Players.LocalPlayer then return error("Module only accessable from client") end
	if not ImageId then ImageId = 64941164 end
	if not Size then Size = 25 end
	if mouseFunction then 
		game:GetService('UserInputService').MouseIconEnabled = false	
		CursorGui.Cursor.Visible = true
		return
	end
	
	local Mouse = game.Players.LocalPlayer:GetMouse()
	
	if not Gui then
		CursorGui = Instance.new('ScreenGui', game.Players.LocalPlayer.PlayerGui)
		CursorGui.Name = "CustomMouseCursor"
		CursorGui.DisplayOrder = 100
                CursorGui.IgnoreGuiInset = true
	else
		CursorGui = Gui
	end
	
	local Cursor = Instance.new('ImageLabel', CursorGui)
	Cursor.AnchorPoint = Vector2.new(0.5,0.5)
	Cursor.Size = UDim2.new(0,Size,0,Size)
	Cursor.ZIndex = 100
	Cursor.BackgroundTransparency = 1
	local success = pcall(function() Cursor.Image = "rbxassetid://"..ImageId end)
	if not success then
		error("Invalid Image Id")
	end
	
	game:GetService('UserInputService').MouseIconEnabled = false
	
	
	mouseFunction = game:GetService('RunService').RenderStepped:Connect(function()
		Cursor.Position = UDim2.new(0,Mouse.X,0,Mouse.Y)
	end)
end

function main:StopUsingMouse()
	if not mouseFunction then return error("Mouse isn't running") end
	if false then
		CursorGui.Cursor.Visible = false
	else
		mouseFunction:Disconnect()
		CursorGui:Destroy()
	end
	game:GetService('UserInputService').MouseIconEnabled = true
end

return main

(Make sure it’s named “CustomMouse” and put inside your localscript!)

Please leave the credits inside the module if you use this! :smiley:

Edit: If you plan on having mobile users, you will have to add code to the “module:StartUsingMouse()” and only let it run if no touchscreen is enabled!

25 Likes

This looks very useful for other people wanting do experiment/Do stuff with the mouse.

1 Like

Seems useful. But what benefits do I receive. Is it just for fun? :face_with_raised_eyebrow::thinking:

Eh, depends on what your using it for. I got tired of the old mouse icon so I made this so it could be custom.

It could be used in games even like Adopt Me, for pc users and stuff

Oh okay, I thought so. Once again you make something great. Thanks :wink:

1 Like

image

I don’t even know if you can see it but yeah that is the custom mouse right under the default one. Why do you add 10 pixels to the x and y? This makes it inaccurate.

And CoreGui elements will overlap the custom mouse. So how exactly is this useful? Like, why can’t someone just do mouse.Icon = "rbxassetid://{id}"?

You do realise mouse.Icon only works when the white cursor is being used, right…?

The default cursor shows when you go to the menu page thing, which is forced.

I have to add 10 pixels so that it shows correctly, at least for the default cursor it does, you may have to modify the module

If you use GUIs, you will barely see the custom cursor so its pretty useless using mouse.Icon.
The whole reason I made this was so that you could see your custom cursor at any time lol

Look, It’s the best I could do with the limitations of ROBLOX, alright?

You can make a feature request or if one already exists, support an existing one.

I’ve made “custom mouse” before, where it used a ScreenGui as well, but the addition of 10 pixels is just so arbitrary. You don’t need to do that, you just need to subtract 36 pixels on the X and Y since that is the gui inset.

And the custom cursor will get buried when you hover over the player list or any other CoreGui element.

:slight_smile:


Also: mouse is 64x64 pixels, not sure why default size is 25.

1 Like

i’m trying to be helpful. besides, i didnt make this specifically for devforum, i just thought it could be used by others. if i didnt make it for my game i wouldnt have made this.

I understand your points about it, but like I said,

It’s the best I can do with what we have this moment.

Also, I fixed the your complaint about adding 10 pixels, hope your happy :confused:

2 Likes

Don’t hackers have control over the client so they can change the image to whatever they want…

They can, but I don’t that it’ll affect gameplay of other users due to it just changing the mouse icon.

1 Like

It wouldn’t matter. If it’s inappropriate then it’s ROBLOXs fault, not mine.

Thanks! I’ll be experimenting with this :grinning:

1 Like

Looks pretty cool. Just note that you don’t have to use “:” in your functions when you are not going to use self. Don’t use it for stylistic reasons.

2 Likes