I have no idea what’s wrong here, it might even be a bug, I’m not sure. So, any help I could really use.
So first off, I’m trying to make it so your pets float next to you using AlignPosition and AlignOrientation. Now the issue occurs when another player comes between the two attachments or is touching the pet, it falls out of the sky. It will then recover after the player has the attachments without any character obstructions. It only has this issue with characters. Here are some demonstrations:
robloxapp-20220722-0754297.wmv (4.7 MB)
and with bigger pets:
robloxapp-20220722-0756441.wmv (1.8 MB)
Here is the code: (It’s on Serverside)
local att1
local att2
local align1
local align2
game.ReplicatedStorage.Equip.OnServerEvent:Connect(function(plr, pet, bool)
if bool == true then
if att1 then
att1:Destroy()
att2:Destroy()
align1:Destroy()
align2:Destroy()
end
if game.Workspace.ActivePets:FindFirstChild(plr.Name.."'s Pet") then
game.Workspace.ActivePets:FindFirstChild(plr.Name.."'s Pet"):Destroy()
end
if plr.Pets:FindFirstChild(pet) then
local clone = game.ReplicatedStorage.Pets:FindFirstChild(pet):Clone()
clone:SetPrimaryPartCFrame(plr.Character.HumanoidRootPart.CFrame)
clone.Name = plr.Name.."'s Pet"
local bound = clone.HitBox.Size
att1 = Instance.new("Attachment")
att1.Parent = plr.Character.HumanoidRootPart
att1.Position += Vector3.new(bound.X+1, bound.Y/2, bound.Z/1.1)
att2 = Instance.new("Attachment")
att2.Parent = clone.PrimaryPart
align1 = Instance.new("AlignPosition", clone.PrimaryPart)
align1.Attachment0 = att2
align1.Attachment1 = att1
align1.MaxForce = math.huge
align1.Responsiveness = 6
align1.RigidityEnabled = true
align2 = Instance.new("AlignOrientation", clone.PrimaryPart)
align2.Attachment0 = att2
align2.Attachment1 = att1
align2.MaxTorque = math.huge
align2.RigidityEnabled = true
clone.Parent = game.Workspace.ActivePets
end
else
if att1 then
att1:Destroy()
att2:Destroy()
align1:Destroy()
align2:Destroy()
end
if game.Workspace.ActivePets:FindFirstChild(plr.Name.."'s Pet") then
game.Workspace.ActivePets:FindFirstChild(plr.Name.."'s Pet"):Destroy()
end
end
end)
game.ReplicatedStorage.DeletePet.OnServerEvent:Connect(function(plr, pet, bool)
if plr.Pets:FindFirstChild(pet) then
plr.Pets:FindFirstChild(pet):Destroy()
end
if bool == true then
if game.Workspace.ActivePets:FindFirstChild(plr.Name.."'s Pet") then
game.Workspace.ActivePets:FindFirstChild(plr.Name.."'s Pet"):Destroy()
end
end
end)
It does the same thing with RigidityEnabled off.