You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
I want to achieve a smooth pet follow system
What is the issue?
the system isnt smooth which i think its because of the loop is there anyway to fix this
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
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:
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.