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)