Hello. I created and scripted pets for a game that I am working on, but for some reason, the pets won’t be aligning accordingly. Here is a video:
https://streamable.com/rjoe3u
Here is my code:
local button = script.Parent;
local function on_Click()
local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent;
if script.Parent.Parent.Parent.Name ~= "Wiggle puff" and script.Parent.Parent.Parent.Name ~= "Cat" then
local tool = game.ReplicatedStorage.InventoryItems:FindFirstChild(script.Parent.Parent.Parent.Name):Clone()
tool.Parent = workspace
local humanoid = player.Character.Humanoid;
if button.Text == "EQUIP" then
humanoid:UnequipTools()
for _, v in ipairs(script.Parent.Parent.Parent.Parent:GetChildren()) do
if v:IsA("Frame") then
v.Inside.TextButton.Text = "EQUIP"
v.Inside.TextButton.BackgroundColor3 = Color3.fromRGB(85, 170, 0)
else
end
end
button.Text = "UNEQUIP"
button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
humanoid:EquipTool(tool)
else
button.Text = "EQUIP"
button.BackgroundColor3 = Color3.fromRGB(85, 170, 0)
humanoid:UnequipTools()
player.Backpack:ClearAllChildren()
end
else
if button.Text == "EQUIP" then
for _, v in ipairs(script.Parent.Parent.Parent.Parent:GetChildren()) do
if v:IsA("Frame") then
v.Inside.TextButton.Text = "EQUIP"
v.Inside.TextButton.BackgroundColor3 = Color3.fromRGB(85, 170, 0)
else
end
end
button.Text = "UNEQUIP"
button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
attachment = Instance.new("Attachment");
attachment.Name = "PetAttachment"
attachment.Parent = player.Character.PrimaryPart
local pet = game.ReplicatedStorage.InventoryItems:FindFirstChild(script.Parent.Parent.Parent.Name);
clone = pet:Clone();
clone.Parent = workspace
clone.Main.AlignOrientation.Attachment1 = attachment
clone.Main.AlignPosition.Attachment1 = attachment
repeat wait()
attachment.Position = Vector3.new(1, -4.2, 0) + clone.Main.Size
until button.Text == "EQUIP"
return
else
button.Text = "EQUIP"
button.BackgroundColor3 = Color3.fromRGB(85, 170, 0)
attachment:Destroy()
clone:Destroy()
end
end
end;
button.MouseButton1Click:Connect(on_Click)