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
Thank you to anyone who can help!