Hi I Making A Pet System But So Laggy Help Please
Code:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
wait(5)
print("e")
wait(5)
local newPet = game.ReplicatedStorage.Pets.MyPet:Clone()
local function setNetworkOwnerOfModel(model, networkOwner)
for _, descendant in pairs(model:GetDescendants()) do
if descendant:IsA("Part") then
if descendant:CanSetNetworkOwnership() then
descendant:SetNetworkOwner(networkOwner)
end
end
end
end
setNetworkOwnerOfModel(newPet, nil)
newPet.Parent = chr
newPet:SetPrimaryPartCFrame(chr["HumanoidRootPart"].CFrame)
local ac = Instance.new("Attachment",chr["HumanoidRootPart"])
ac.Visible = false
ac.Name = "ACharacter"
ac.Position = Vector3.new(0,1,2) * newPet.PrimaryPart.Size
local ap = Instance.new("Attachment",newPet.PrimaryPart)
ap.Visible = false
ap.Name = "APet"
local alignPosition = Instance.new("AlignPosition")
alignPosition.MaxForce = 25000
alignPosition.Attachment0 = ap
alignPosition.Attachment1 = ac
alignPosition.Responsiveness = 25
alignPosition.Parent = newPet
local alignOrientation = Instance.new("AlignOrientation")
alignOrientation.MaxTorque = 25000
alignOrientation.Attachment0 = ap
alignOrientation.Attachment1 = ac
alignOrientation.Responsiveness = 25
alignOrientation.Parent = newPet
game.ReplicatedStorage.RemoteEvent:FireClient(plr,alignPosition,alignOrientation,ac,ap,newPet)
end)
end)