How to position custom mouse properly

I couldn’t find this or I just search wrong but whatever

I have this script

local module = {}

--local RunService = game:GetService("RunService")

local Frame = script.Parent.Parent.Parent

local MouseFrame = Frame:WaitForChild("Mouse")

local MyMouse = game:GetService("Players").LocalPlayer:GetMouse()

local function PositionMouse()
	MouseFrame.Position = UDim2.new(0, MyMouse.X, 0.015, MyMouse.Y)
end

MyMouse.Move:Connect(function()
	PositionMouse()
end)

return module

(I have no idea why I didn’t connect it straight to function but it changes nothing anyway)

Mouse image label have anchor point 0.5, 0.5

If I don’t put scale Y at position it will be above the mouse

I think correcting it with scale can help but I noticed that if I cut screen with output thing, mouse will be positioned wrong which means it will be different at different screen sizes

Is there any fix?

I also noticed that in my other game the custom cursor which is just dot located perfectly without scale correction (I tried using it and changing image but it was just located above again)

(It is still above mouse at 0.015 scale)

This topic should lead you in the right direction (even if it doesn’t directly solve your post…)

1 Like

I’m bad at math and can’t guess what I have to do with absolute position

I can rewrite that for you here

local module = {}
local MouseFrame = script.Parent.Parent.Parent.Mouse
local mouse = game.Players.LocalPlayer:GetMouse()

local function uLocation()
	local locationX= mouse.X - MouseFrame.AbsolutePosition.X
	local locationY= mouse.Y - MouseFrame.AbsolutePosition.Y
	MouseFrame.Position = UDim2.new(0,locationX,0,locationY)
end
mouse.Move:Connect(uLocation)
1 Like

Oh well I thought about that, but (again) thought it’s wrong

Thanks to DrMystery, with his link I found out that u can get mouse position with UserInputService and it fixed the problem (Atleast in studio surely)

local module = {}

--local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local Frame = script.Parent.Parent.Parent

local MouseFrame = Frame:WaitForChild("Mouse")

local MyMouse = game:GetService("Players").LocalPlayer:GetMouse()

local function PositionMouse()
	local MLoc = UserInputService:GetMouseLocation()
	MouseFrame.Position = UDim2.new(0, MLoc.X, 0, MLoc.Y)
end

MyMouse.Move:Connect(function()
	PositionMouse()
end)

return module

I also tested his fix and it have located mouse too far at right (maybe because anchor point 0.5), but maybe his fix works too

(Actually its perfect kinda in studio only) (Fixed withscale offsets)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.