Hi, devforum. I wanted to make one of a swarm of object(for example: pets)'s bodypositoin to be at a part when I click on the part. The problem is i’m stuck on the pets part. Idk how I make only one pet go to the part.
Here’s the code:
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
local hrp = plr.Character.HumanoidRootPart
local pets = hrp:FindFirstChild("pet1","pet2","pet3","pet4","pet5")--this line of code is cringeeeeee
pets.BodyPosition.Position = script.Parent.Position
end)
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
local hrp = plr.Character.HumanoidRootPart
for i,v in pairs(hrp:GetChildren()) do
if v.Name:lower():find('pet') then
v.BodyPosition.Position = script.Parent.Position
end
end
pets.BodyPosition.Position = script.Parent.Position
end)
FindFirstChild takes one argument and returns one instance whereas :GetChildren returns all of the children of a specific instance.