Custom mouse is not centered

hello, i was following a post (How to create a custom mouse cursor and a custom clickdetector cursor) that showed you how to make a custom GUI with a custom clickdetector cursor too (which is why im not using the normal method of changing the mouse gui) and i have realised that the imagelabel that the mouse uses is not actually centered.

Modified code below

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local cursorGui = script.Parent
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")

-- Mouse hovering events
local mousehovered = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("Mouse"):WaitForChild("MouseHovered")
local mouseunhovered = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("Mouse"):WaitForChild("MouseUnhovered")

-- Hide default cursor
--UserInputService.MouseIconEnabled = false

-- Update cursor position
mouse.Move:Connect(function()
	cursorGui.CustomCursor.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
	cursorGui.ClickDetectorCursor.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
end)

-- Show custom cursor
cursorGui.CustomCursor.Visible = true

-- Hide custom click detector cursor initially
cursorGui.ClickDetectorCursor.Visible = false

UserInputService.InputChanged:Connect(function(InputObject, GameProcessedEvent)
	if InputObject.UserInputType == Enum.UserInputType.MouseMovement and not GameProcessedEvent then
		if mouse.Target and mouse.Target:FindFirstChildWhichIsA("ClickDetector") then
			cursorGui.CustomCursor.Visible = false
			cursorGui.ClickDetectorCursor.Visible = true
		else
			cursorGui.CustomCursor.Visible = true
			cursorGui.ClickDetectorCursor.Visible = false
		end
	end
end)

mousehovered.OnClientEvent:Connect(function()
	cursorGui.CustomCursor.Visible = false
	cursorGui.ClickDetectorCursor.Visible = true
end)

mouseunhovered.OnClientEvent:Connect(function()
	cursorGui.CustomCursor.Visible = true
	cursorGui.ClickDetectorCursor.Visible = false
end)```

any help appreciated :)
1 Like

Try turning the inset in the ScreenGui to none

ive already done that, but i figured out that i could just make a frame with UIPadding inside of it and it works as intended (as long as “Interactable” is disabled)

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