# I am having a Mouse Problem for a Drawing GUI

So I am trying to make a Drawing GUI as said on the Title, that I want to make my mouse draw within the GUI Frame, but when I draw, It goes offset of the GUI Frame as shown on the video below.

I think [Ink.Position] is the problem and I tried to fit it with scale, offset and either divided it or multiplied it for UDim2 on the photo below

The Position of the GUI Frame is {0.6, 0},{0.3, 0} and the Size of the GUI is {0.3, 0},{0.6, 0}.

Thanks for reading and I’d appreciate if someone would help

I assume you’re calling Move() with the Mouse.X and Mouse.Y values inside a Mouse.Move connection. The thing is that Mouse.X and Mouse.Y are in terms of absolute position, meaning it gives you the distance of the mouse from the top and the left in pixels, irrespective of on which GUIObject you click on. Feeding this absolute position directly into the position thus results in inaccuracy, since GUIObject.Position’s scale is dependent on the parent (the relative points for x = 0 and y = 0 are changed, so to speak)

Here’s a function that will convert (hopefully) absolute position to position in Udim2

local function AbsToUDim(target, x, y)
local convX, convY
-- Parent absolute position
local parAbsX = target.Parent.AbsolutePosition.X
local parAbsY = target.Parent.AbsolutePosition.Y
-- Absolute size
local parAbsSizeX = target.Parent.AbsoluteSize.X
local parAbsSizeY = target.Parent.AbsoluteSize.Y
-- Relative absolutePosition within parent
local relAbsX = x - parAbsX
local relAbsY = y - parAbsY
-- Convert relAbs to scale (w/ respect to size)
convX = UDim.new(relAbsX / parAbsSizeX, 0)
convY = UDim.new(relAbsY / parAbsSizeY, 0)
-- Return converted
return UDim2.new(convX, convY)
end

Now you can do this:

Ink.Position = AbsToUDim(Ink, IntX, IntY)

I believe this should solve your problem but I haven’t tested the logic and the functioning at all, please excuse any problems at tell me about them.

P.S. You should change anchor point to 0,0 so the label is exactly where it is supposed to be

4 Likes

This is a long shot in terms of the script working but I’m fairly confident the problem stems from the required conversion

It’s kinda offset from the mouse, and I don’t think I would have ever figured out your method

Mmm might be due to the parent’s anchor point, what’s the anchor point of wherever the Ink object goes?

I checked before and it was {0,0}, do I have to change the anchor point to fix it to the right position?

since its offset down a bit, maybe in the code make it go up a bit

For anyone who stumbles on this from Google results like me, make sure either your ScreenGui has IgnoreGuiInset set to True, OR make sure you some how account for the offset of the Roblox gui inset using [GuiService:GetGuiInset] when placing your frames (GuiService | Documentation - Roblox Creator Hub)

1 Like