Hello, everybody, I need help with a script. So I am making an inventory system that I already coded two pets into it. The problem is that the dog will not appear in the char but the cat will .
I equipped both pets but only the cat appears in character
here is the script
Local Script
local Equip = script.Parent
local template = script.Parent.Parent.Parent.Parent.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")
Equip.MouseButton1Click:Connect(function() -- when player clicks Equip, the Equip is a Ui that prompts players
Equip.Text = "Equipped"
local EquippedValue = template:WaitForChild("EquippedValue")
EquippedValue.Value = "Equipped" -- value in template to store info
template.check.ImageColor3 = Color3.fromRGB(82, 170, 55)
for _, child in pairs(template:GetChildren()) do -- checking all children of template
if child:IsA("Folder") and child.Name == "Cat" then
print("Cat is a valid child of template")
local pet = child.Name
EquipPet:FireServer(pet)
wait(0.1)
child:Destroy()-- to stop the remote event from firing
elseif child:IsA("Folder") and child.Name == "Dog" then -- confirming that child is the Dog
print("Dog is a valid child of template") -- this is print statement i am talking about
local pet = child.Name
EquipPet:FireServer(pet)
child:Destroy()
end
end
end)
here is an example of what the template looks like
ServerScript(Second Script)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")
EquipPet.OnServerEvent:Connect(function(player,pet)
local char = player.Character
print(pet)
local humroot = char.HumanoidRootPart
if pet == "Cat" then
local Cat = game.ReplicatedStorage.Pets.BasicEggPets.Cat:Clone()
if Cat ~= nil and char ~= nil then
Cat:SetPrimaryPartCFrame(humroot.CFrame)
local modelSize = Cat.PrimaryPart.Size
local attachmentCharacter = Instance.new("Attachment")
attachmentCharacter.Visible = false
attachmentCharacter.Parent = humroot
attachmentCharacter.Position = Vector3.new(1,-5.5,0) + modelSize
local attachmentPet = Instance.new("Attachment")
attachmentPet.Visible = false
attachmentPet.Parent = Cat.PrimaryPart
local alignPosition = Instance.new("AlignPosition")
alignPosition.MaxForce = 25000
alignPosition.Attachment0 = attachmentPet
alignPosition.Attachment1 = attachmentCharacter
alignPosition.Responsiveness = 25
alignPosition.Parent = Cat
local AlignOrientation = Instance.new("AlignOrientation")
AlignOrientation.MaxTorque = 25000
AlignOrientation.Attachment0 = attachmentPet
AlignOrientation.Attachment1 = attachmentCharacter
AlignOrientation.Responsiveness = 25
AlignOrientation.Parent = Cat
Cat.Parent = char
elseif pet == "Dog" then
local Dog = game.ReplicatedStorage.Pets.BasicEggPets.Dog:Clone()
if Dog ~= nil and char ~= nil then
Dog:SetPrimaryPartCFrame(humroot.CFrame)
local modelSize = Dog.PrimaryPart.Size
local attachmentCharacter = Instance.new("Attachment")
attachmentCharacter.Visible = false
attachmentCharacter.Parent = humroot
attachmentCharacter.Position = Vector3.new(1,-5.5,0) + modelSize
local attachmentPet = Instance.new("Attachment")
attachmentPet.Visible = false
attachmentPet.Parent = Dog.PrimaryPart
local alignPosition = Instance.new("AlignPosition")
alignPosition.MaxForce = 25000
alignPosition.Attachment0 = attachmentPet
alignPosition.Attachment1 = attachmentCharacter
alignPosition.Responsiveness = 25
alignPosition.Parent = Dog
local AlignOrientation = Instance.new("AlignOrientation")
AlignOrientation.MaxTorque = 25000
AlignOrientation.Attachment0 = attachmentPet
AlignOrientation.Attachment1 = attachmentCharacter
AlignOrientation.Responsiveness = 25
AlignOrientation.Parent = Dog
Dog.Parent = char-- I parent it here
end
--end
end
end
end)
There is no errors in the output