I'm trying to make a bezier curve that goes to the mousepos but I don't know how to get rid of the balls in the curve

What do I want to achieve?
I want to create a Bezier curve with spheres from the players head to the mouse position like TreeLands , for now I need to know how to delete them better (Picture below is a screenshot from TreeLands)
image

What is the issue?
The balls aren’t deleting and reappearing smoothly

What solutions have I tried?
I have tried deleting all the parts in the folder but it looks like in the video

local value = player.Values.IsCarrying
local char = player.Character
local head = char:FindFirstChild("Head")
local runservice = game:GetService("RunService")
local TweenService = game:GetService('TweenService')
local mouse = player:GetMouse()
local part = Instance.new("Part")
part.Shape = Enum.PartType.Cylinder
part.Size = Vector3.new(0.1, 4, 4)
part.Orientation = Vector3.new(0, 90, 90)
part.CanQuery = false
part.Anchored = true
part.CanCollide = false
local folder = Instance.new('Folder')
folder.Name = "Local"
folder.Parent = char
part.Parent = folder

local function lerp(a, b, t)
	return a + (b - a) * t
end

local function quadraticBezier(t, p0, p1, p2)
	local l1 = lerp(p0, p1, t)
	local l2 = lerp(p1, p2, t)
	local quad = lerp(l1, l2, t)
	return quad
end

part.Parent = char

mouse.Move:Connect(function()
	
	local target = mouse.Target
	if target then
		if target:IsDescendantOf(char) or target == part then return end
	end
	
	local tween = game:GetService('TweenService'):Create(part, TweenInfo.new(.05), {Position = mouse.hit.p})
	tween:Play()
	
	local p2 = Vector3.new(((head.Position+ mouse.Hit.Position)/2).X, mouse.Hit.Position.Y + 15, ((head.Position+ mouse.Hit.Position)/2).Z)
	
	for i,v in pairs(folder:GetChildren()) do
		v:Destroy()
	end
	
	for i = 0.1,1,0.1 do
		local model = Instance.new("Part"):Clone()
		model.Shape = Enum.PartType.Ball
		model.Size = Vector3.one
		model.Anchored = true
		model.Name = i
		model.Parent = folder
		model.CanCollide = false
		model.CanQuery = false
		folder.Parent = char
		
		model.Position = quadraticBezier(i, head.Position,p2,mouse.Hit.Position)
		task.wait()
	end
end)

This is my first ever devforum post so If you don’t understand I am sorry.

you can use run service for that and

try folder:ClearAllChildren()

local function lerp(a, b, t)
	return a + (b - a) * t
end

local function quadraticBezier(t, p0, p1, p2)
	local l1 = lerp(p0, p1, t)
	local l2 = lerp(p1, p2, t)
	local quad = lerp(l1, l2, t)
	return quad
end

part.Parent = char

runservice.RenderStepped:Connect(function()
	local target = mouse.Target
	if target then
		if target:IsDescendantOf(char) or target == part then return end
	end

	local tween = game:GetService('TweenService'):Create(part, TweenInfo.new(.05), {Position = mouse.hit.p})
	tween:Play()

	local p2 = Vector3.new(((head.Position+ mouse.Hit.Position)/2).X, mouse.Hit.Position.Y + 15, ((head.Position+ mouse.Hit.Position)/2).Z)

	folder:ClearAllChildren()

	for i = 0.1,1,0.1 do
		local model = Instance.new("Part"):Clone()
		model.Shape = Enum.PartType.Ball
		model.Size = Vector3.one
		model.Anchored = true
		model.Name = i
		model.Parent = folder
		model.CanCollide = false
		model.CanQuery = false
		folder.Parent = char

		model.Position = quadraticBezier(i, head.Position,p2,mouse.Hit.Position)
	end
end)

Now only one ball is shown
image

Nevermind this solution works, I just needed to also remove the task.wait()

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.