Error with attempt to compare number <= UDim2

I made a system for writing and I wanted there to be an option for an eraser. But I’m having trouble with the eraser button.

When the eraser key is pressed, the frame’s visible property is set to true and it goes into erase mode. No other action should be taken. No writing, no drawings, etc. If the player presses the eraser button one more time (to close it) the value of that frame will be false.

Output:


function EraseAroundPosition(position, radius)
	for _, child in ipairs(drawingFrame:GetChildren()) do
		local childPosition = child.Position
		local distance = (Vector2.new(childPosition.X.Offset, childPosition.Y.Offset) - position).Magnitude
ERROR-->    if distance <= radius then
			child:Destroy() 
		end
	end
end
All relevant code
script.Parent.MainBackground.Header.Background.Buttons.erase.MouseButton1Click:Connect(function()
	if isDrawing then
		ToggleDrawingMode()
	end
	ToggleErasingMode()
end)

game:GetService("RunService").RenderStepped:Connect(function()
	if eraseInProgress then
		local cursorPosition = Vector2.new(mouse.X, mouse.Y)
		EraseAroundPosition(cursorPosition, cursorSize) 
	end
end)


game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if isErasing then
			eraseInProgress = true
			return
		end
	end
end)

game:GetService("UserInputService").InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if isErasing and eraseInProgress then
			eraseInProgress = false
			return 
		end
	end
end)

local radius = UDim2.new(0, 10, 0, 10) 
function EraseAroundPosition(position, radius)
	for _, child in ipairs(drawingFrame:GetChildren()) do
		local childPosition = child.Position
		local distance = (Vector2.new(childPosition.X.Offset, childPosition.Y.Offset) - position).Magnitude
		if distance <= radius then
			child:Destroy() 
		end
	end
end
Hierarchy

image

Thank you to anyone who can help!

1 Like

You’re comparing a magnitude with a UDim2.

You haven’t defined cursorSize and you’ve repeated the name of radius in the erase function parameters.

1 Like

I’m sorry I couldn’t understand you. What should I do?

Cursorsize should be a number and don’t compare with radius