You can customize the appearance and behavior of a user's mouse icon within your experience to create a cohesive style across all of your UI elements. This includes temporarily changing the user's mouse icon in specific circumstances, such as clicking a button or while the mouse hovers over another user.
You can change the user's mouse icon in a LocalScript by setting the MouseIcon property in UserInputService to a custom Roblox asset ID. For example, the following LocalScript changes the user's default mouse icon to a black circle with a blue dot in the middle:
local UserInputService = game:GetService("UserInputService")UserInputService.MouseIcon = "rbxassetid://3400146391"
Because the mouse icon is set in a LocalScript, each user can have a different icon, or can have an icon appear in certain situations, such as when an ability is recharging or the mouse is hovering over a hostile target.
You can hide the user's mouse icon by setting the UserInputService.MouseIconEnabled to false in a LocalScript. For example, the following code switches the mouse icon from visible to invisible and back every two seconds:
local UserInputService = game:GetService("UserInputService")while true dotask.wait(2)UserInputService.MouseIconEnabled = falsetask.wait(2)UserInputService.MouseIconEnabled = trueend
You can lock the mouse icon position to the screen using UserInputService.MouseBehavior with a value of MouseBehavior.LockCurrentPosition or MouseBehavior.LockCenter. When you set this property back to MouseBehavior.Default, the mouse icon unlocks and can move anywhere on the screen again.
If a user's mouse icon is locked in a position, UserInputService.InputChanged still fires when the user moves the mouse, passing in the distance the mouse has moved. For example, the following code sample locks the user's mouse icon after one second, then Studio prints the mouse delta whenever the user moves their mouse:
local UserInputService = game:GetService("UserInputService")task.wait(1)UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPositionUserInputService.InputChanged:Connect(function(inputObject)if inputObject.UserInputType == Enum.UserInputType.MouseMovement thenprint("Mouse delta is (" .. tostring(inputObject.Delta.X) .. ", " .. tostring(inputObject.Delta.Y) .. ")")endend)