Argument 1 Missing or Nil

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 :slight_smile:

1 Like

SCRIPT 1 HAS BEEN SOLVED! IGNORE SCRIPT 1! (Thanks a lot)

1 Like

The problem in script 2 is possibly the ā€œtrueā€ you put inside the replicatedStorage reference line

1 Like
	local clonedPet = game.ReplicatedStorage.Pets:FindFirstChild(petName, true):Clone()

What is that true argument?
Does that pet have a boolValue inside of it? if so, donā€™t do that, and find that bool as the child of the pet

1 Like

Is PetName defined correctly?
(Char limit)

1 Like

Other than this, I donā€™t see any other errors in the script.

Check if everything is defined/spelt correctly

1 Like

ā€˜petNameā€™ is defined correctly. The ā€˜trueā€™ argument is required.

the argument is not required it is optional

2 Likes

Could you send the bit where the PetName is defined please?

1 Like

Hold on just tested and it works now. :expressionless: Mustā€™ve just done something. Anyways, thanks for the help!

2 Likes

Ok glad it works. No problem!
(char limit)

1 Like

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.

https://developer.roblox.com/en-us/api-reference/function/Instance/FindFirstChild

How did you solve it? I cant solve myself. Its polarisprog