Hey all devs! I am just creating a pet system and I received two errors.
Both errors say Argument 1 missing or nil.
Script 1:
local function onEquip()
if selectedTemplate ~= nil then
if selectedTemplate:FindFirstChild("Equipped").Value == false then
-- error is on next line
local result = replicatedStorage.EggHatchingRemotes.EquipPet:InvokeServer(selectedTemplate)
if result == "Equip" then
selectedTemplate.Checkmark.Visible = true
equipBTN.Text = "Unequip"
selectedTemplate:FindFirstChild("Equipped").Value = true
elseif result == "Unequip" then
equipBTN.Text = "Equip"
selectedTemplate.Checkmark.Visible = false
selectedTemplate:FindFirstChild("Equipped").Value = false
end
else
local result = replicatedStorage.EggHatchingRemotes.UnequipPet:InvokeServer(selectedTemplate)
if result == true then
equipBTN.Text = "Equip"
selectedTemplate.Checkmark.Visible = false
selectedTemplate:FindFirstChild("Equipped").Value = false
end
end
end
end
Script 2:
game.ReplicatedStorage.EggHatchingRemotes.EquipPet.OnServerInvoke = function(player, petName)
local numberOfPetsEquipped = #workspace.Player_Pets:FindFirstChild(player.Name):GetChildren()
if (numberOfPetsEquipped + 1) <= player.Values.MaxPetsEquipped.Value then
--error is on next line
local clonedPet = game.ReplicatedStorage.Pets:FindFirstChild(petName, true):Clone()
clonedPet.Parent = workspace.Player_Pets:FindFirstChild(player.Name)
return "Equip"
elseif (numberOfPetsEquipped + 1) > player.Values.MaxPetsEquipped.Value then
return "Cannot Equip"
end
end
All help is strongly appreciated. Thanks for your time!
Regards,
Flash
FindFirstChild()'s second parameter is its recursive parameter, when the value passed as its second argument is true a recursive search is performed for an instance of a name that is specified/indicated by the methodās first argument.