Hello everybody,
I am making a script where if a player clicks on a bag or chest then the pet will position itself and attack the bag. The issue is that if there is more than 1 pet. The pets all go in the same position and I was wondering if there was a way to position the pets differently.
For Example, if I have 5 pets and I want to position each pet in the specified position above how would I do that? So far I have a value that takes count of the number of pets equipped.
This is what I have so far
local CD = script.Parent -- click detector
local Hitbox = script.Parent.Parent
game.Players.PlayerAdded:Connect(function(plr)
local function DetectClick(playerWhoClicked)
-- CD function
local amountequuippedvalue = plr.PlayerGui.Inventory.LowerInvFrame.AmountEquipped.AmountEquippedValue-- value used to track the specified amount of pets equipped
local character = playerWhoClicked.Character:GetChildren() or playerWhoClicked.CharacterAdded:Wait():GetChildren()-- getting char
for _,pet in pairs(character) do
if pet ~= nil then
if pet:IsA("Model") then
-- if can a print, it will print the pet name ex:Dragon
print("Pet Found")
pet:PivotTo(Hitbox.CFrame)
local alignPosition = pet:WaitForChild("AlignPosition")
local alignOrientation = pet:WaitForChild("AlignOrientation")
local attachmentpet = pet.PetHitBox:WaitForChild("Attachment")
local atttachmentTarget = Hitbox.Attachment
-- all these attachments and constrainst were created before hand
attachmentpet.Parent = pet.PrimaryPart
alignPosition.Attachment0 = attachmentpet
alignPosition.Attachment1 = atttachmentTarget
alignPosition.Parent = Hitbox
-- for positioning the pet
alignOrientation.Attachment0 = attachmentpet
alignOrientation.Attachment1 = atttachmentTarget
alignOrientation.Parent = Hitbox
-- for rotating the pet
if amountequuippedvalue.Value == 1 then
atttachmentTarget.Position = Vector3.new(0,0,4)
elseif amountequuippedvalue.Value == 2 then
atttachmentTarget.Position = Vector3.new(6,0,0)
atttachmentTarget.Orientation = Vector3.new(0,87,0)
elseif amountequuippedvalue.Value == 3 then
atttachmentTarget.Orientation = Vector3.new(0,185,0)
atttachmentTarget.Position = Vector3.new(0,0,-4)
elseif amountequuippedvalue.Value == 4 then
atttachmentTarget.Position = Vector3.new(-5,0,0)
atttachmentTarget.Orientation = Vector3.new(0,-90,0)
elseif amountequuippedvalue.Value == 5 then
atttachmentTarget.Position = Vector3.new(0,0,3)
end
end
else
print("There was a issue with the pet loading")
end
end
end
CD.MouseClick:Connect(DetectClick)
end)
Note: I am not exactly asking for script(would be appreciated tho) just for something that can help me like an article.