My football is being really laggy

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want the ball to move smoothly

  1. What is the issue? Include screenshots / videos if possible!

  1. What solutions have you tried so far?

I have looked into Network Ownership but it doesn’t seem to be helping and I don’t think that that’s the issue

This is my code for the ball

local Animation = script.KickAnimation
local player = game.Players.LocalPlayer
local Character = player.Character
local Humanoid = Character:WaitForChild ("Humanoid")
local Anim = Humanoid:LoadAnimation(Animation)


script.Parent.MouseButton1Up:Connect(function()
	local folder = workspace.BallStorer

	for i,v in pairs(folder:GetChildren()) do

		if v.Name == "ShootBall" then
			if v.Owner.Value == player.Name then
				v.Touch.Enabled = false
				
				local Number = math.round((script.Parent.Parent.Frame.Size.Y.Offset/443)*100)
				script.Parent.Parent.Number.Value = Number
				script.Parent.Parent.Visible = false

				
				

				Anim:Play()
				wait(0.6)

				local HasBall = player.HasBall.Value
				
				
				local ball = v

				for _,v in ipairs(player.Character.UpperTorso:GetDescendants()) do
					if v:IsA("Weld") then
						v:Destroy()
					end
				end

				ball.Parent = workspace
		

				local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart").Position

				local forceDirection = (humanoidRootPart - ball.Position).unit
				forceDirection = Vector3.new(forceDirection.x, -1, forceDirection.z)

				local forceMagnitude = player.PlayerGui.HitNetLesson.Frame.Number.Value*-1.55


				ball.Velocity = forceDirection * forceMagnitude


			end
			
		end
	end	
end)

Thank you!

2 Likes

I would recommend looking into Remote Events and Functions | Documentation - Roblox Creator Hub

You should not set the parent, set the velocity and change the descendants of a part in a localscript. You have to fire a remote event through a localscript and handle them through a serverside script.

A localscript changes only what the player sees on their screen. Therefore, the ball would only move in your screen, hence the choppy movements. Instead, use Remote Events to make the ball move for everyone with specific parameters (Such as the velocity [Direction Only, not the magnitude] which should be calculated locally).

2 Likes

Thank you! I shall try it tomorrow!

It works! Thanks a tonne! Really appreciate it

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