Argument 1 missing or nil?

So this is my code;

Check.Checkit = function(player, open1, open2, frame, about)
	if open1 == true and open2 == true then 
		if about == "Sword" then
			for i, v in pairs(frame.ItemView:GetChildren()) do
				EquipEvent:FireServer( "UnEquip", v, v.AttackScript.Animation.Id.Value)
			end
		elseif about == "Inv" then
			if #player.PlayerGui.Inventory.Character.Sword:GetChildren() == 1 then
				print("Something is currently equipped!")
			else
				frame.Parent = player.PlayerGui.Inventory.Character.Sword
				frame.Size = UDim2.new(1,0,1,0)
				frame.Position = UDim2.new(0.5,0,0.5,0)
				for i, v in pairs(frame.ItemView:GetChildren()) do
					local serial = v.Stats.Serial.Value
					EquipEvent:FireServer( "Equip", v.Name, v.AttackScript.Animation.Id.Value, serial)
				end
			end
		end
	end
end

This the the script which fires the event, now before this script, a local script calls this module:

local Inv_Open = player.PlayerGui.Inventory.Inventory.Opened
local Char_Open = player.PlayerGui.Inventory.Character.Opened
local frame = script.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Parent.Parent.Name == "Sword" then
		local clone = script.Parent.Parent:Clone()
		script.Parent.Parent:Destroy()
		clone.Parent = player.PlayerGui.Inventory.Inventory.Inventory
		EquipEvent:FireServer("UnEquip")
		Check.Checkit(player, Inv_Open.Value, Char_Open.Value, frame, "Sword")
	elseif script.Parent.Parent.Parent.Name == "Inventory" then
		Check.Checkit(player, Inv_Open.Value, Char_Open.Value, frame, "Inv")
	end
	
end)

Now, after all of this when the server gets the event this is the script:

Event.OnServerEvent:Connect(function(player, state, item, animation, serial)
	local char = player.Character or player.CharacterAdded:Wait()
	local Humanoid = player.Character:FindFirstChildOfClass("Humanoid")
	local bp = player.Backpack:FindFirstChild(item)
	local charitem = char:FindFirstChild(item)
	if state == "Equip" then 
		print(item)
		Humanoid:EquipTool(bp)
		char.Animate.toolnone:WaitForChild("ToolNoneAnim").AnimationId = "http://www.roblox.com/asset/?id="..animation
		Update.UpdateWeapon(player, serial)
	elseif state == "UnEquip" then
		Update.UpdateWeapon(player, 0)
		Humanoid:UnequipTools(charitem)
	end
end

So now as you can see in the first script on line 4 it says ItemView is not a valid member of image label.
but as you can see later on in that script its the same line and that works? So I am not sure what the problem is there and also it says Argument 1 missing or nil Which is this line:

local bp = player.Backpack:FindFirstChild(item)

in the third script. If someone can help me fix this issue, that would be appreciated.

When firing this event, you only put 1 argument, so, “state” but then, item, animation and serial are nil values. To fix that, you need to do :

EquipEvent:FireServer("UnEquip", "Sword", etc.)
1 Like

This is NOT correct, the nil value comes from variable assignment, it’s just that the argument is missing.

local function argc(...)
   return select('#', ...);
end;
print(argc()) --> 0
print(argc(nil)) --> 1
print(argc(nil, nil)) --> 2

As for the OP, you didn’t insert any arguments into FireServer thus the nil comes (via the parameter assignment, not by the argument)
I’d add something into the argument as you didn’t insert any argument into that.

1 Like

I have fixed the issue with the argument, it’s just the ItemView is not a valid member of ImageLabel:

Check.Checkit = function(player, open1, open2, frame, about)
	if open1 == true and open2 == true then 
		if about == "Sword" then
			for i, v in pairs(frame.ItemView:GetChildren()) do -- This Doesn't work
				EquipEvent:FireServer( "UnEquip", v, v.AttackScript.Animation.Id.Value)
			end
		elseif about == "Inv" then
			if #player.PlayerGui.Inventory.Character.Sword:GetChildren() == 1 then
				print("Something is currently equipped!")
			else
				frame.Parent = player.PlayerGui.Inventory.Character.Sword
				frame.Size = UDim2.new(1,0,1,0)
				frame.Position = UDim2.new(0.5,0,0.5,0)
				for i, v in pairs(frame.ItemView:GetChildren()) do -- This does work
					local serial = v.Stats.Serial.Value
					EquipEvent:FireServer( "Equip", v.Name, v.AttackScript.Animation.Id.Value, serial)
				end
			end
		end
	end
end

The first for loop doesn’t work as it gets an error, but the second one does?