Help with Custom Mouse

Hello! I have an issue with this custom mouse script. The image is not on the mouse position, I tried to subtract the value of the mouse X position, but doesn’t work either. :disappointed:

Video.

Script.
--Variables--
local player = game.Players.LocalPlayer; --Gets the local player
local mouse = player:GetMouse(); --Gets the mouse
local customMouse = script.Parent --Gets the image of the custom mouse

--Main Function--
local function move()
	customMouse.Position = UDim2.new(0, mouse.X, 0, mouse.Y) --Sets the image position to the mouse position
end

game:GetService("RunService"):BindToRenderStep("MoveCustomMouse", 10, move) --Uses BindToRenderStep for better perfomance
game:GetService("UserInputService").MouseIconEnabled = false --Disables the mouse

--Tuguicraft
Solution I tried, but doesn't work.
--Variables--
local player = game.Players.LocalPlayer; --Gets the local player
local mouse = player:GetMouse(); --Gets the mouse
local customMouse = script.Parent --Gets the image of the custom mouse

--Main Function--
local function move()
    local mouseXposition = mouse.X - 0.5
	customMouse.Position = UDim2.new(0, mouseXposition, 0, mouse.Y) --Sets the image position to the mouse position
end

game:GetService("RunService"):BindToRenderStep("MoveCustomMouse", 10, move) --Uses BindToRenderStep for better perfomance
game:GetService("UserInputService").MouseIconEnabled = false --Disables the mouse

--Tuguicraft

The topbar imposes an inset of 36 pixels, so you just have to subtract by that inset.

I also recommend you only move when the mouse moves, not every render frame. I also discourage the use of mouse when you can use UserInputService for all this.

local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")

local GUI_INSET = GuiService:GetGuiInset()

local custom_mouse = script.Parent --Gets the image of the custom mouse

UserInputService.InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseMovement then
        local mouse_location = UserInputService:GetMouseLocation() - GUI_INSET
        custom_mouse.Position = UDim2.fromOffset(mouse_location.X, mouse_location.Y)
    end
end)
3 Likes

Still not working, same position as the video above. I don’t think is the topbar because is the X axis, not the Y one.

Works fine for me.

Does it help if you set AnchorPoint to 0.5, 0.5?

1 Like

Yes, I changed the value of the AnchorPoint and now works. Thank you so much!

1 Like

Why not use

custom_mouse.Position = UDim2.fromOffset(mouse_location.X, mouse_location.Y)

?

It’s much quicker

1 Like

That’s exacly what the script says. May you explain more?

He edited his post to add it. fromOffset just takes two inputs and leaves the scale vales the same. So if they’re 0, they’ll stay zero and it will just change the offset. The same goes for fromScale but flipped.

2 Likes