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.
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)
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.