Hi everyone I have wrote a script for a pet equip system and it is in with my leader stats so ignore that part but anyways. I am trying to make a system that equips my pets I have and the hatching system works and everything is pretty good and works. But my problem is that I have the script to equip the pets in my leader stats and it will not equip the pet. I will change the value of the equipped pet but nothing happens. Thank you for your help and here is my script:
local function equipPet(player,pet)
local character = player.Character
if pet == nil and character == nil then
if character:FindFIrstChild(player.Name.."'s pet") then character(player.Name.."'s pet"):Destroy() end
if character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy()
end
pet.Name = player.Name.."'s pet"
pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
local modelSize = pet.PrimaryPart.size
local attachmentCharacter = Instance.new("Attachment")
attachmentCharacter.Visible = false
attachmentCharacter.Name = "attachmentCharacter"
attachmentCharacter.Parent = character.HumanoidRootPart
attachmentCharacter.Position = Vector3.new(1,1,0) + modelSize
local attachmentPet = Instance.new("Attachment")
attachmentPet.Visible = false
attachmentPet.Parent = pet.PrimaryPart
local allignPosition = Instance.new("AlignPosition")
allignPosition.MaxForce = 25000
allignPosition.Attachment0 = attachmentPet
allignPosition.Attachment1 = attachmentCharacter
allignPosition.Responsiveness = 25
allignPosition.Parent = pet
local allignOrientation = Instance.new("AlignOrientation")
allignOrientation.MaxTorque = 25000
allignOrientation.Attachment0 = attachmentPet
allignOrientation.Attachment1 = attachmentCharacter
allignOrientation.Responsiveness = 25
allignOrientation.Parent = pet
pet.Parent = character
end
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 10000
cash.Parent = leaderstats
local Inventory = Instance.new("Folder")
Inventory.Name = "PetInventory"
Inventory.Parent = player
local equippedPet = Instance.new("StringValue")
equippedPet.Name = "EquippedPet"
equippedPet.Parent = player
player.CharacterAdded:Connect(function(char)
if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
end
end)
equippedPet.Changed:Connect(function()
if equippedPet.Value == nil then
if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
end
end
end)
end)