hi! I have this pet script that is supposed to spawn in the equipped pet once the player’s character loads in. it doesn’t return any errors and the script to spawn in the pet and move it around was working perfectly before I added the function to check attributes.
here’s the code:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
for _, pet in ipairs(player.Inventory.Pets:GetChildren()) do
if pet:GetAttribute("ActivePet") and pet:GetAttribute("Owner") == player.Name then
if player and character then
local humRootPart = character.HumanoidRootPart
local newPet = pet:Clone()
newPet.Parent = character
local bodyPos = Instance.new("BodyPosition", pet.cube)
bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
local bodyGyro = Instance.new("BodyGyro", pet.cube)
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
while wait() do
bodyPos.Position = humRootPart.Position + Vector3.new(2.5,-1,2.5)
bodyGyro.CFrame = humRootPart.CFrame
end
end
end
end
end)
end)
here’s the explorer hierarchy for where pets are:
and here’s the attributes of the pet:
I’ve verified that attributes are updating as they should, so I think its just a problem with the script. idk how to fix this, can anyone help?
when the player gets in the game.loop through every pets the player has and set the “Owner” name to the player’s name and set the equipped pet’s “ActivePet” to true…Now check …! If this works then ok…
ok when u run the game, go to the localplayer and see if the equipped pet’s “ActivePet” is true or not and check the “Owner” attribute also…maybe u can find a clue or two. Then inform me…ok?
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "Inventory"
local pet = Instance.new("Part", folder)
pet.Name = "MyPet"
pet:SetAttribute("ActivePet", true)
pet:SetAttribute("Owner", plr.Name)
plr.CharacterAdded:Connect(function(char)
for _, pet in ipairs(plr.Inventory:GetChildren()) do
if pet:GetAttribute("ActivePet") and pet:GetAttribute("Owner") == plr.Name then
if plr and char then
local humRootPart = char.HumanoidRootPart
local newPet = pet:Clone()
newPet.Parent = char
local bodyPos = Instance.new("BodyPosition", pet)
bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
local bodyGyro = Instance.new("BodyGyro", pet)
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
while wait() do
bodyPos.Position = humRootPart.Position + Vector3.new(2.5,-1,2.5)
bodyGyro.CFrame = humRootPart.CFrame
end
end
end
end
end)
end)```
but the pet doesn't move around ..U need another script to move the pet..maybe..
okay I added prints and I think I found the main issue. it looks like if pet:GetAttribute("ActivePet") is returning false for all pets no matter when I run the code, even if it’s been manually set to true. idk how to fix that though