Mouse.Move fires too slow to simulate drawing (gaps appear when moving the mouse fast)

Hello. I made a drawing UI, but, whenever I try to move my mouse fast, it misses some points that my mouse has passed on. Here is a video that explains it:
https://streamable.com/aa5l6c
Here is the code that I wrote:

local frame = script.Parent.DrawArea;
local runService = game:GetService("RunService");
local userInputService = game:GetService("UserInputService");
local isOn = false;
local isDown = false;
local mouse = game:GetService("Players").LocalPlayer:GetMouse();

function on_Enter()
	isOn = true
end;

function on_Leave()
	isOn = false
end;

function on_Move()
	if not isOn then return end;
	if not isDown then return end;
	
	local draw = script.Draw;
	local clone = draw:Clone();
	clone.Size = UDim2.new(0.204 * (script.Parent.DrawSize.Value * .3), 0, 0.408 * (script.Parent.DrawSize.Value * .3), 0)
	clone.Parent = frame;
	clone.Position = UDim2.new(0, mouse.X, 0, mouse.Y) - UDim2.new(0, clone.Parent.AbsolutePosition.X, 0, clone.Parent.AbsolutePosition.Y)
end

coroutine.resume(coroutine.create(function()
	while wait() do
		if userInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) and isOn then
			isDown = true
		else
			isDown = false
		end
	end
end))

frame.MouseEnter:Connect(on_Enter)
frame.MouseLeave:Connect(on_Leave)
mouse.Move:Connect(on_Move)

(If I use a wrong method of drawing please mention)

I believe this problem has occurred before in this post, although it seems to be unsolved.

Yeah judging by this the solution seems to interpolate between the points using @goldenstein64 method.

1 Like