Issue with how my drawing board's pixels appear

All I am trying to do is have ink be directly where my mouse cursor is for convenience, but it has been driving me insane and I cannot find any possible way to fix it.

The issue is coming from the position of the newpixel

local function createPixel(position, color, player)
	local newPixel = InkTemplate:Clone()
	-- Adjust position to align directly with the cursor
	newPixel.Position = UDim2.new(0, position[1] - newPixel.Size.X.Offset / 2, 0, position[2] - newPixel.Size.Y.Offset / 2)
	newPixel.BackgroundColor3 = color
	newPixel.Name = player.Name .. "_Pixel"
	newPixel.Parent = CanvasFrame -- Ensure new pixels are parented to CanvasFrame
	print("Created new pixel for player:", player.Name, "at position:", position, "with color:", color)
end

What I have tried so far is to see how/what could be the potential issue with my UDim2, and I tried to tweak it but it did not do much of a thing for it.
This is how the pixel will appear:


And just to show how I would expect it, it would be mostly like this for example
image


Any help would be greatly appreciated, as I do not know what my potential issue could be, but I did note that the anchor point of the Ink is 0.5,0.5:

Currently I have took a break from this as it has been super frustrating for me.

hmm.

just set the position to (0, position[1], 0, position[2])
how do the pixels spawn? send a photo if you can!

how are you getting position? send the script block if you can!

send a picture of your hierachy (explorer) with all of the frames. (surface or screen gui?)

anyway those are all my questions. i have to :sleeping: but hopefully someone else can make use of your answers!

hello, thank you for the idea, however this did not correct the issue unfortunately. I also am confused as to what you mean by how one, I am getting the ‘position,’ when that already is shown, and two, as I show the pixels spawn and how that looks.

however, here is the structure.

also given the fact that this is what is cloned to appear on the canvas.

and this is that same thing, but how it positions.

(Moreover, I am speculating the issue is at hand with the position logic.)

What do you need the AnchorPoint for?

the origin of my frame’s position. (it basically centers it)

I feel like the AnchorPoint could be the problem, just compare the actual AbsolutePosition and the Position of the pixel, but I don’t really understand the purpose of centering drawn pixels, why do you need it?

It is cause it is accuracy and alignment, since the cursor is involved. Frames use the top left corner as the anchor point (0,0)

How can you have it both centered and depend on the cursor position? I’d just check with no AnchorPoint anyway

the key is that your position must be interpreted as the center, not the top-left corner.
I also want it to have precision when I use the sketch board. even other apps like MS-Paint would operate in that same way as example.

what I wonder is… Is there an issue with my logic on client script?

DrawScreen.Canvas.MouseButton1Down:Connect(function(x, y)
	isDrawing = true
	print("Client sending DrawPixel action at position:", x, y)
	Interaction:FireServer("DrawPixel", { x, y })
end)

DrawScreen.Canvas.MouseButton1Up:Connect(function()
	isDrawing = false
end)

DrawScreen.Canvas.MouseMoved:Connect(function(x, y)
	if isDrawing then
		print("Client sending DrawPixel action at position:", x, y)
		if pcall(function() Interaction:FireServer("DrawPixel", { x, y }) end) then
			-- No error occurred
		else
			warn("Error firing DrawPixel action")
		end
	end
end)


Is this how you want it to be?

indeed, something just like this… and it already has the behavior of being held down.

What did I do wrong?

Well, that thing, does NOT use anchor points

Interesting…So what is your fetch?

I still don’t know what you wanted the anchor point for, did you want to have the pixel’s center match the cursor’s position?

Yeah. I guess you could say that. (Im not that pro at coding so bear with me.)

Subtract half of the pixel size from the position and it should be centered like that

so then would it appear just exactly as this?

newPixel.Position = UDim2.new(0, position[1] /2, 0, position[2]/2)

(Again, I am not that much of a pro.)

No, in the client code where you send the position (MouseMoved) you’d have to do something like this:

....
if isDrawing then
    x -= (pixel.Size.X.Offset / 2) --In your case this number is 10 so if you're not planning on changing the pixel sizes and keeping it as 20, you can just replace this calculation with x -= 10
    y -= (pixel.Size.X.Offset / 2) --Same thing as above
    --rest of code here
end
....

well. I see. In that case, how can I figure out that global ‘pixel?’ it is not defined in my client script.