Hello.
I am currently attempting to make a barrier where you need a specific amount of pets to go through. I thought this would work by making it go through a for loop, however i get the error attempt to compare number and Instance. Not sure what is caused by this, and would like some help. Here's my script:
local Player = game:GetService("Players").LocalPlayer local PetFolder = Player:WaitForChild("Pets") local Barrier = workspace:WaitForChild("5 Pets Barrier").Barrier:FindFirstChild("Main Barrier") for _, PetAmount in pairs(PetFolder:GetDescendants()) do if PetAmount >= 5 then Barrier.CanCollide = false Barrier.BrickColor = BrickColor.new("Lime green") end end
I am stuck on this and would like some help. Thanks
PetAmount in this case will be the actual pet object. You can't compare an object to a number. To fix this, just do:
if #PetFolder:GetChildren() >= 5 then Barrier.CanCollide = false Barrier.BrickColor = BrickColor.new("Lime green") end
#PetFolder:GetChildren()
gets the length of the array of pets in the folder.