Image not appearing over the cursor?

Since you can’t change the cursor that pops up when hovering over a GUI object (TextButton, ImageButton) I’m trying to disable the cursor, and put an ImageLabel of the cursor on top of the cursor.
But, the cursor will not appear. The image is approved.
Code:

game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui'):SetTopbarTransparency(1) -- this is sample code from Developer Hub
player = game.Players.LocalPlayer
mouse = player:GetMouse()
--[[
mouse.Icon = "http://www.roblox.com/asset/?id=4002059853"]]--
local userInputService = game:GetService("UserInputService")

userInputService.MouseIconEnabled = false
-- UserInputService code is from Roblox Developer Hub, too
local GUI = Instance.new("ScreenGui")
GUI.Name = "GUI"
GUI.Parent = player.PlayerGui
local Image = Instance.new("ImageLabel")
Image.Name = "Mouse"
Image.Size = UDim2.new(0, 15, 0, 25)
Image.Parent = GUI
Image.Image = "rbxassetid://4002059853"
while wait() do
	Image.Position = UDim2.new(mouse.X, mouse.Y)
end

Thanks,
OldBo5.

1 Like

You are incorrectly using UDim2.new, which expects four parameters (scaleX, offsetX, scaleY, offestY). Image.Position = UDim2.new(mouse.X, mouse.Y) manipulates the scaleX and offsetX, which sends the UI element off the screen.

image

Correct usage in this case would be Image.Position = UDim2.new(0, mouse.X, 0, mouse.Y). You also need to set the BackgroundTransparency of the ImageLabel to 1.

You don’t need this much code to set the mouse icon though. Most of the logic here can be replaced simply with:

game:GetService("Players").LocalPlayer:GetMouse().Icon = "rbxassetid://4002059853"
4 Likes