Should my pets following system be client or server?

Basically i’m gonna revamp my pets following system as i need to make it more smooth adding gyro and body velocity and some other stuff. But i see other games have it on their client and my pet system works just fine doesn’t really lag that much. But i don’t know where to put it, please help.

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

RunService.Heartbeat:Connect(function()
	if #script.Parent:GetChildren() - 1 == 1 then
		local Pet = script.Parent:FindFirstChildOfClass("Part")
		local Character = script.Parent.Parent
		TweenService:Create(Pet, TweenInfo.new(0.3), {["CFrame"] = Character.HumanoidRootPart.CFrame * CFrame.new(0,0,7.5)}):Play()
		Pet.CFrame = CFrame.lookAt(Pet.Position, Character.HumanoidRootPart.Position)
	elseif #script.Parent:GetChildren() - 1 == 2 then
		local PetNum = 1
		for i, v in pairs(script.Parent:GetChildren()) do
			if v:IsA("Part") then
				local Pet = v
				local Character = script.Parent.Parent
				if PetNum == 1 then
					TweenService:Create(Pet, TweenInfo.new(0.3), {["CFrame"] = Character.HumanoidRootPart.CFrame * CFrame.new(0,0,7.5)}):Play()
				elseif PetNum == 2 then
					TweenService:Create(Pet, TweenInfo.new(0.3), {["CFrame"] = Character.HumanoidRootPart.CFrame * CFrame.new(5,0,5)}):Play()
				end
				PetNum += 1
				Pet.CFrame = CFrame.lookAt(Pet.Position, Character.HumanoidRootPart.Position)
			end
		end
	elseif #script.Parent:GetChildren() - 1 == 3 then
		local PetNum = 1
		for i, v in pairs(script.Parent:GetChildren()) do
			if v:IsA("Part") then
				local Pet = v
				local Character = script.Parent.Parent
				if PetNum == 1 then
					TweenService:Create(Pet, TweenInfo.new(0.3), {["CFrame"] = Character.HumanoidRootPart.CFrame * CFrame.new(0,0,7.5)}):Play()
				elseif PetNum == 2 then
					TweenService:Create(Pet, TweenInfo.new(0.3), {["CFrame"] = Character.HumanoidRootPart.CFrame * CFrame.new(5,0,5)}):Play()
				elseif PetNum == 3 then
					TweenService:Create(Pet, TweenInfo.new(0.3), {["CFrame"] = Character.HumanoidRootPart.CFrame * CFrame.new(-5,0,5)}):Play()
				end
				PetNum += 1
				Pet.CFrame = CFrame.lookAt(Pet.Position, Character.HumanoidRootPart.Position)
			end
		end
	end
end)
2 Likes

Server so that other players can see your pet.

(Not sure if how that works btw lol)

Yes but people use client to loop to every player and changing it that way so either way it’s visable

1 Like

Use client, TweenService runs smoother on client anyways.

This is not related to whether it should be server or client but it is important to performance. Although TweenService does work, Lerping is prefered. It is both easier on the CPU and does not require all those TweenService:Create()s.

1 Like

You might want to use AlignPosition on the Client to save yourself unnecessary heartbeat functions.

2 Likes

Try setting the pet’s network owner to the player who owns it. Now the client handles physics for it.

1 Like

Server should only process information and the client should do all the visuals, in your situation the server is supposed to tell the client what kind of pets each player has & when they get equipped/unequipped so you can make them follow that player.

2 Likes