I am using PolarisProg’s advanced pet system tutorial, but I got this error on this script.
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PetsFolder = workspace:WaitForChild("PlayerPets")
local Spacing = 5
local PetSize = 3
local MaxClimbHeight = 6
local RayParams = RaycastParams.new()
local RayDirection = Vector3.new(0,-500,0)
local function RearrangeTables(Pets, Rows, MaxRowCapacity)
table.clear(Rows)
local AmountOfRows = math.ceil(#Pets / MaxRowCapacity)
for i = 1, AmountOfRows do
table.insert(Rows, {})
end
for i, v in Pets do
table.insert(Rows, v)
end
end
local function GetRowWidth(Row, Pet)
if Pet then
local SpacingBetweenPets = Spacing - Pet.PrimaryPart.Size.X
local RowWidth = 0
if #Row == 1 then
return 0
end
for i, v in Row do
if i ~= #Row then
RowWidth += Pet.PrimaryPart.Size.X + SpacingBetweenPets
else
RowWidth += Pet.PrimaryPart.Size.X
end
end
return RowWidth
end
end
RunService.Heartbeat:Connect(function(Deltatime)
for _, PlayerPetFolder in PetsFolder:GetChildren() do
if not Players:FindFirstChild(PlayerPetFolder.Name) then return end
local Character = Players[PlayerPetFolder.Name].Character or Players[PlayerPetFolder.Name].CharacterAdded:Wait()
local HumanoidRootPart = Character.PrimaryPart
local Humanoid = Character:WaitForChild("Humanoid")
if not Character or not Humanoid or not HumanoidRootPart then return end
local Pets = {}
local Rows = {}
for _, v in PlayerPetFolder:GetChildren() do
table.insert(Pets, v)
end
RayParams.FilterDescendantsInstances = {PetsFolder, Character}
local MaxRowCapacity = math.ceil(math.sqrt(#Pets))
RearrangeTables(Pets, Rows, MaxRowCapacity)
for i, Pet in Pets do
local RowIndex = math.ceil(i / MaxRowCapacity)
local Row = Rows[RowIndex]
local RowWidth = GetRowWidth(Row, Pets)
local XOffset = #Row == 1 and 0 or RowWidth/2 - Pet.PrimaryPart.Size.X/2
local X = (table.find(Row, Pet) -1) * Spacing
local Z = RowIndex * Spacing
local Y = 0
local RayResult = workspace:Blockcast(Pet.PrimaryPart.CFrame * Vector3.new(0, MaxClimbHeight, 0), Pet.PrimaryPart.Size, RayDirection, RayParams)
if RayResult then
Y = RayResult.Position.Y + Pet.PrimaryPart.Size.Y / 2
end
local TargetCFrame = CFrame.new(HumanoidRootPart.CFrame.X, 0, HumanoidRootPart.CFrame.Z) * HumanoidRootPart.CFrame.Rotation * CFrame.new(X - XOffset, Y, Z)
Pet.PrimaryPart.CFrame = Pet.PrimaryPart.CFrame:Lerp(0.1)
end
end
end)
Error (line 29):
Players.Waddletastic.PlayerScripts.PetFollower:29: attempt to index nil with 'Size' - Client - PetFollower:29