Spray Can tool leaves gaps when cusor moves to fast

I’m making a spray paint tool but I have a problem when I move the cusor fast gaps are left

This is the local spript in the tool(this is only a section of the script)

local function calculateSprayInfo()
	local userInputService = game:GetService("UserInputService")

	local mouseVP = userInputService:GetMouseLocation()
	local mouseRay = workspace.CurrentCamera:ViewportPointToRay(mouseVP.x, mouseVP.y)
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Blacklist
	params.FilterDescendantsInstances = {workspace.SprayPaint, Player.Character, workspace.Monster, workspace.Waypoints, workspace.SpawnLocation} -- Put the new spray paint parts in that model so it can ignore them

	local result = workspace:Raycast(mouseRay.Origin, mouseRay.Unit.Direction * 300, params)

	-- Wall Painting here
	print(result)
	if result ~= nil then
		sprayEvent:FireServer(result.Position, result.Normal)
		
		generatedSound = spray:Clone()
		generatedSound.PlayOnRemove = false
		generatedSound.Parent = script
		generatedSound:Play()
	end
end

Server Script in server script service:

local sprayEvent = game.ReplicatedStorage.Remotes.SprayEvent

sprayEvent.OnServerEvent:Connect(function(player, pos, normal)
	local p = game:GetService("ReplicatedStorage"):WaitForChild("Cylinder"):Clone()
	p.Parent = workspace.SprayPaint
	p.CanCollide = false
	p.Anchored = true
	p.CFrame = CFrame.new(pos, pos + normal)
	p.Color = Color3.new(1, 0.952941, 0.278431)
end)
1 Like

This is basically your problem, you’re going to have to use some maths to fill in the gaps between points

1 Like

can you help me out this is what I have so far

local function calculateSprayInfo()
	local userInputService = game:GetService("UserInputService")

	local mouseVP = userInputService:GetMouseLocation()
	local mouseRay = workspace.CurrentCamera:ViewportPointToRay(mouseVP.x, mouseVP.y)
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Blacklist
	params.FilterDescendantsInstances = {workspace.SprayPaint, Player.Character, workspace.Monster, workspace.Waypoints, workspace.SpawnLocation} -- Put the new spray paint parts in that model so it can ignore them

	local result = workspace:Raycast(mouseRay.Origin, mouseRay.Unit.Direction * 300, params)
	
	if frame1 == nil then
		frame1 = result.Position
	end
	frame2 = result.Position
	
	local cylinder = game:GetService("ReplicatedStorage").Cylinder:Clone()
	cylinder.Parent = workspace.SprayPaint
	cylinder.CanCollide = false
	cylinder.Anchored = true
	local midpointFormula = (frame2.X - frame1.X)^2 + (frame2.Y - frame1.Y)^2

	print(midpointFormula)
	cylinder.Color = Color3.new(1, 0.952941, 0.278431)
	
	-- Wall Painting here
	print(result)
	if result ~= nil then
		sprayEvent:FireServer(result.Position, result.Normal)
		
		generatedSound = spray:Clone()
		generatedSound.PlayOnRemove = false
		generatedSound.Parent = script
		generatedSound:Play()
	end
	
	frame1 = result.Position
end

Did you ever find the solution to the problem?

yes chatgpt helped me a bit (30 words)