Laggy Soccer Ball - How do I make it smoother?

Hello!

So I am trying to script a simple soccer ball where if it is touched it will move in that direction.

The problem is that the ball looks like this in action:

The ball is extremely laggy, and teleports from place to place as it is kicked.

There are currently two server scripts inside the ball.

One sets the ball onto the server:

local ball = script.Parent
while true do
	wait(5)
ball:SetNetworkOwner(nil)
end

and the other moves the ball:

local Services = {
	Players = game:GetService("Players"),
	Debris = game:GetService("Debris")
}


local Settings = {
	Kick_Cooldown = .8,
}
local Ball = script.Parent
local KickSound = Ball:WaitForChild("Kick")
local IgnoreTable = {}

Ball.Touched:Connect(function(Part)
	local Character = Part.Parent
	if not Character then
		return
	end
	local Player = Services.Players:GetPlayerFromCharacter(Character)
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	local Root = Character:FindFirstChild("HumanoidRootPart")
	if not Player or not Humanoid or Humanoid.Health <= 0 or not Root or table.find(IgnoreTable, Player) then
		return
	end
	table.insert(IgnoreTable, Player)

	delay(Settings.Kick_Cooldown, function()
		if not Player then
			return
		end
		local Position = table.find(IgnoreTable, Player)
		if not Position then
			return
		end
		table.remove(IgnoreTable, Position)
	end)

	local Direction = CFrame.lookAt(Root.Position, Ball.Position).LookVector
	local Kick_Force = 20
	if Direction.Magnitude < 0.001 then
		return
	end
	if Ball:GetAttribute('LastTouch') ~= nil then
		if Ball:GetAttribute('LastTouch') ~= Player.Name then
			local st = Ball:GetAttribute('LastTouch')
			Ball:SetAttribute('LastTouch', Player.Name)
			Ball:SetAttribute('SecondTouch', st)
		else

		end
	else
		Ball:SetAttribute('LastTouch', Player.Name)
	end
	Ball:SetNetworkOwner(Player)
	local TeamName = Player:GetAttribute('TeamName')
	game.ServerStorage.GameFolder.Standings:FindFirstChild(TeamName):SetAttribute('Touches', game.ServerStorage.GameFolder.Standings:FindFirstChild(TeamName):GetAttribute('Touches') + 1)
	local Velocity = Instance.new("BodyVelocity")
	Velocity.Parent = Ball
	Velocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
	Velocity.Velocity = (Direction.Unit * Kick_Force * 2.7) + Vector3.new(0, Kick_Force * 2.1, 0)
	
	Services.Debris:AddItem(Velocity, 0.2)
	
	KickSound:Play()
end)

So does anyone have any idea what I am doing wrong?
How can I make it so the ball moves at least a little smoother and doesn’t seem to teleport?

Thanks for reading!

Does it have something to do with this? I just noticed this, would I have to set it back to the server afterwards, or should I not even change it to be on the players network in the first place?

(Edit: yes removing this does fix that lag)

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