Argument 1 missing or nil

I wanted to make an item drop from an inventory thingy when you press the imagebutton but for some reason it says “Argument 1 missing or nil” when i press the button,how can i fix it?

I tried looking on devforum but im kinda dumb so i wasnt able to understand anything

Here are the scripts:

LocalScript (inside the imagebutton)

local Button = script.Parent
local itemN = Button.Parent.Name.Text
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
Button.Activated:Connect(function()
	if workspace.Inventories[player.Name]:FindFirstChild(itemN).Value > 0 then -- Error there
		ReplicatedStorage.Drop:FireServer(itemN)
	else
		
	end	
end)

ServerScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage.Drop.OnServerEvent:Connect(function(player,itemN)
	if workspace.Inventories[player.Name] then
		if workspace.Inventories[player.Name]:FindFirstChild(itemN) then
			local ItemValue = workspace.Inventories[player.Name]:FindFirstChild(itemN)
			if ItemValue.Value > 0 then
				ItemValue.Value -= 1
				local Clone = ServerStorage.Items[itemN]
				Clone.Name = itemN
				Clone.Parent = workspace
				Clone.Position = player:FindFirstChild("HumanoidRootPart").Position
			end
		end
	end
end)

Thanks in advance

1 Like

It’s because itemN doesn’t exist, put the local itemN line inside the Activated event and before the if statement

local Button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer

Button.Activated:Connect(function()
	local itemN = Button.Parent.Name.Text
	if workspace.Inventories[player.Name]:FindFirstChild(itemN).Value > 0 then -- Error there
		ReplicatedStorage.Drop:FireServer(itemN)
	else
		
	end	
end)
1 Like

It still says “Argument 1 missing or nil”

I think you should try debugging and see if the value exists before trying to compare it with a number, or if even the parent (workspace.Inventories[player.Name]) exists

Could you give the line and script it occurs on? Or show the line highlighted when you click on the error? (It won’t highlight for replicated local scripts so you may have to find it manually)

The error occurs on line 6 in the local script

It was because i named a textlabel Name,after i changed it to IName it worked

1 Like