Name
it was working all find one second then the next i load in and it starts bugging
09:51:41.023 Workspace.lu877t77t.Pet_Follower:17: attempt to index nil with ‘WaitForChild’ - Client - Pet_Follower:17
> local runService = game:GetService("RunService")
>
> local playerPets = workspace:WaitForChild("Player_Pets")
>
> local circle = math.pi * 2
>
> local function getPosition(angle, radius)
> local x = math.cos(angle) * radius
> local z = math.sin(angle) * radius
> return x, z
> end
>
> local function positionPets(character, folder)
> for i, pet in pairs(folder:GetChildren()) do
> local petSpeed = 0.2
> local Attachment = pet.PrimaryPart:WaitForChild("Attachment")
> local BillboardGui = Attachment:WaitForChild("BillboardGui")
> local PetName_Txt = BillboardGui:WaitForChild("PetName")
> local PetRarity_Txt = BillboardGui:WaitForChild("PetRarity")
> BillboardGui.Enabled = true
> PetName_Txt.Text = pet.Name
> PetRarity_Txt.Text = pet:GetAttribute("Rarity_Name")
> PetRarity_Txt.TextColor3 = pet:GetAttribute("Rarity_Color")
>
> local radius = 4+#folder:GetChildren()
> local angle = i * (circle / #folder:GetChildren())
> local x, z = getPosition(angle, radius)
> local _, characterSize = character:GetBoundingBox()
> local _, petSize = pet:GetBoundingBox()
>
> local offsetY = - characterSize.Y/2 + petSize.Y/2
> local sin = (math.sin(15 * time() + 1.6)/.5)+1
> local cos = math.cos(7 * time() + 1)/4
>
> if character.Humanoid.MoveDirection.Magnitude > 0 then
> if pet:FindFirstChild("Walks") then
> pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, offsetY+sin, z) * CFrame.fromEulerAnglesXYZ(0,0,cos), petSpeed))
> else
> pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, offsetY/2+math.sin(time()*3)+1, z), petSpeed))
> end
> else
> if pet:FindFirstChild("Walks") then
> pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, offsetY, z) , petSpeed))
> pet:PivotTo( CFrame.new( pet.PrimaryPart.Position, character.PrimaryPart.Position ) )
> else
> pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(character.PrimaryPart.CFrame * CFrame.new(x, offsetY/2+math.sin(time()*3)+1, z) , petSpeed))
> end
> end
> end
> end
>
> runService.RenderStepped:Connect(function()
> for _, PlrFolder in pairs(playerPets:GetChildren()) do
> local Player = game.Players:FindFirstChild(PlrFolder.Name) or nil
> if Player ~= nil then
> local character = Player.Character or nil
> if character ~= nil then
> positionPets(character, PlrFolder)
> end
> end
> end
> end)