Pet following system lagging and not smooth

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

  1. What do you want to achieve?
    I want to achieve a smooth pet follow system

  2. What is the issue?
    the system isnt smooth which i think its because of the loop is there anyway to fix this

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?

havent found a solution yet

local Disabled = false
local Player = game.Players:FindFirstChild(script.Parent.Parent.Name)


if Player then
	while wait() do
		if Player.Character.Health ~= 0 then
			if not Disabled then
				local Pos = script.Parent:WaitForChild("Pos").Value
				local BG = script.Parent.PrimaryPart.BodyGyro
				local BP = script.Parent.PrimaryPart.BodyPosition
				local d = Player.Character.HumanoidRootPart.Position.Y - script.Parent.PrimaryPart.Position.Y
				BP.Position = (Player.Character.HumanoidRootPart.Position + Pos) - Vector3.new(0,Player.Character.HumanoidRootPart.Size.Y/2,0) + Vector3.new(0,script.Parent.PrimaryPart.Size.Y/2,0) + Vector3.new(0,game.ServerScriptService.PetSystem.globalPetFloat.Value,0)
				if Player.Data.isWalking.Value == false then
					BG.CFrame = CFrame.new(script.Parent.PrimaryPart.Position, Player.Character.HumanoidRootPart.Position - Vector3.new(0, d, 0))
				else
					BG.CFrame = Player.Character.HumanoidRootPart.CFrame
				end
			else
				script.Parent:Destroy()
				break
			end
		else
			Disabled = false
		end
	end
end

https://gyazo.com/5cf078178228f9a5ce91c7943a154b31

2 Likes

YOU ARE USING INSANELY OUTDATED INSTANCES BRUH :skull:
Also why are you simulating it on a server?
You have to simulate it locally to not affect network speed

3 Likes

I want you to please reconsider what you are doing.
You have been making posts like these for a while now, and there is a clear pattern: there is poorly written code.
You have been called out for your bad coding practices on these older posts, yet you keep repeating them everytime without any sign of improval. As a reminder:

  • Please cache variables before initiating the loop. Restating them everytime the loop runs makes it slower
  • Not everything needs a loop, and in your older posts, all of them use loops that run every frame, which is very inefficient for certain tasks
  • And specifically for this one, you want to manage a pet following system like this on the client, that way it is more responsive for the player who owns the pet.

I don’t know if you are making a youtube video, or if you are just trolling, but I just wanted to put this out here for future readers.
Examples:

2 Likes

mate im generally stuck i used to script back in the days but ive forgotten

1 Like

Your pets look fine for how you’re moving them… for 7 pets. Maybe try 5 at most. I’m sure things will work out better.

Who cares… Clearly he is having problem with this. I think he is just pushing it a bit too far with so many pets. That’s no reason to be rude.

1 Like

Thank you for that i wondering if there is anyway you can like change the script so it loops but without while wait() if you know what i mean

Let me see if I can dig up one of mine…

This is just a snippet. This is totally flawless as it moves.

Smooth follow

In fact I’ll message it to you…

I have more refined versions of this now, but this was the one that opened the door.

1 Like

I never insulted him in my message. The “youtube video, or trolling” part could easily be infered from the fact that he keeps repeating the same mistakes, even after being called out for them, but I never attacked him as a person, or discouraged him from seeking solutions.
→ In my message I also provide many improvements that he could implement in his code, I did not just put that message out without trying to help.

1 Like

nah i get where ur coming from icl but honestly bro im confused im so used to scripting with while wait()

theres still no solution ive found and its bugging me

Stop using wait()! Use task.wait()

1 Like