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!
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!