Drawing Error on Position

Hey, I created a drawing system by using a SurfaceGui, while drawing it works but about the position, the draws spawns at the bottom left corner of the surface, (the surfacegui is on the baseplate), Heres what I did to position.

script.Parent.OnServerEvent:Connect(function(Player, X, Y) -- mouse x and y
	local Ball = Instance.new('ImageLabel',workspace.Baseplate.SurfaceGui.MainFrame)
	Ball.Size = UDim2.new(0,10,0,10)
	Ball.Position = UDim2.new(0,workspace.Baseplate.Size.X - X,0,workspace.Baseplate.Size.Y - Y)
	Ball.ImageTransparency = 1
	Ball.BackgroundColor3 = Color3.new(1, 1, 1)

	local UICorner = Instance.new('UICorner',Ball)
	UICorner.CornerRadius = UDim.new(0,90)
end)

The surface gui 's size is set to 1,0,1,0.

1 Like

You’re using workspace.Baseplate.Size.X - X and workspace.Baseplate.Size.Y - Y , which is not the best way to position the ball on the surface. Instead, you should use X / workspace.Baseplate.Size.X and Y / workspace.Baseplate.Size.Y to get the relative position of the mouse click on the Baseplate surface, and then pass that to the first argument in UDim2.new for the position of the ball.

Edit:

script.Parent.OnServerEvent:Connect(function(Player, X, Y) -- mouse x and y
	local Ball = Instance.new('ImageLabel', workspace.Baseplate.SurfaceGui.MainFrame)
	Ball.Size = UDim2.new(0, 10, 0, 10)
	Ball.Position = UDim2.new(X / workspace.Baseplate.Size.X, 0, Y / workspace.Baseplate.Size.Y, 0)
	Ball.ImageTransparency = 1
	Ball.BackgroundColor3 = Color3.new(1, 1, 1)

	local UICorner = Instance.new('UICorner', Ball)
	UICorner.CornerRadius = UDim.new(0, 90)
end)

This should make it work.

I have one question, do I have to use Mouse.Hit.Position or just Mouse.X and Mouse.Y?

You can use either depending on what you want.

Mouse.Hit.Position gives the world position of the mouse click, while Mouse.X and Mouse.Y give the screen position of the mouse click.

If you want to position the ball on the surface of the Baseplate relative to the screen, you can use Mouse.X and Mouse.Y .

If you want to position the ball on the surface of the Baseplate relative to the world, you need to use Mouse.Hit.Position and convert it to the local coordinates of the Baseplate.

I tried both and its still not appearing in where I clicked.

I thinnk issue lies with the calculation of the ball’s position. Can you try debugging it?

I used a remote event to give the Server the Mouse Hit Position and I ran your script but its literally not on the map anymore.

I was drawing at the middle of the map and it gave approximated positions like {-0.01, 0},{0, 0}.

try this

script.Parent.OnServerEvent:Connect(function(Player, X, Y)
	local Ball = Instance.new('ImageLabel', workspace.Baseplate.SurfaceGui.MainFrame)
	Ball.Size = UDim2.new(0, 10, 0, 10)
	Ball.Position = UDim2.new(X, 0, Y, 0)
	Ball.ImageTransparency = 1
	Ball.BackgroundColor3 = Color3.new(1, 1, 1)

	local UICorner = Instance.new('UICorner', Ball)
	UICorner.CornerRadius = UDim.new(0, 90)

	wait()
end)

If the issue still persists, try printing the values of X and Y to the output to see what values they have, and ensure that they are within the expected range.

It looks like the Y position seems to always be 0, I tried positioning on a normal UI and it was on the top left corner of the screen, but too gone to the left.

I think the issue might be with the way you’re setting the Position of the ImageLabel .

Try this:

script.Parent.OnServerEvent:Connect(function(Player, X, Y)
	local Ball = Instance.new('ImageLabel', workspace.Baseplate.SurfaceGui.MainFrame)
	Ball.Size = UDim2.new(0, 10, 0, 10)
	Ball.Position = UDim2.new(0, X, 0, Y)
	Ball.ImageTransparency = 1
	Ball.BackgroundColor3 = Color3.new(1, 1, 1)

	local UICorner = Instance.new('UICorner', Ball)
	UICorner.CornerRadius = UDim.new(0, 90)
end)

You may also need to adjust the values of X and Y to correctly position the ball where the mouse was clicked.

Where the mouse was clicked has a X,Y,Z and its different than placing it in a UI thats a Vector2, since the Frame has 1,0,1,0 the size is different, the space to click is different and when changing places its different, I think thats what happening, but I don’t know whats the solution.

Since I have put to be 1,0,1,0, that Size is the total size of the Adornee in scale, which confuses more.