Invalid argument #1 to 'pairs' (table expected, got nil)

What “you” is:

local theirItems = {
	"Sinister Branches"
}

What the script using it is:

local trade = game.ReplicatedStorage.Trade
local yourPlr = game.Players.LocalPlayer
local tradebox = script.Parent
local rs = game.ReplicatedStorage

trade.OnClientEvent:Connect(function(theirPlr,yourPlr,them,you)
	for i,v in pairs(them) do
		if rs:WaitForChild("Hats") then
			local hats = rs.Hats
			if hats:WaitForChild(v) then
				if hats[v].ImageID then
					tradebox.Them["Them"..i].Image = "rbxassetid://"..hats[v].ImageID.Value
					tradebox.Them["Them"..i].InUse.Value = true
					tradebox["ThemRap"..i].Text = hats[v].RecentAveragePrice.Value
					tradebox.Them["Them"..i].ItemName.Value = v
				end
			end
		end
	end
	
	print(typeof(you)) -- prints as "nil"
	for i,v in pairs(you) do -- this is where it errors
		if rs:WaitForChild("Hats") then
			local hats = rs.Hats
			if hats:WaitForChild(v) then
				if hats[v].ImageID then
					tradebox.You["You"..i].Image = "rbxassetid://"..hats[v].ImageID.Value
					tradebox.You["You"..i].InUse.Value = true
					tradebox["YouRap"..i].Text = hats[v].RecentAveragePrice.Value
					tradebox.You["You"..i].ItemName.Value = v
				end
			end
		end
	end
end)

How are you firing the event? What are you sending as the arguments? I think you probably messed something up with the ordering

1 Like

this is the send trade script:

local plr = game.Players.AgentHeIIfire
local youItems = {
	"Shaggy",
	"Take a Chance",
	"Sk12r Boi"
}
local theirItems = {
	"Sinister Branches"
}

if plr then
	game.ReplicatedStorage.Trade:FireServer(plr,plr,youItems,theirItems)
end

this is what processes it back to a gui

local trade = game.ReplicatedStorage.Trade

trade.OnServerEvent:Connect(function(plr1,plr2,items1,items2)
	trade:FireClient(plr1,plr2,items1,items2)
end)

(the last one is what is connected to by the main local script)

Okay your issue is taht FireClient expects the client to fire the event to as the first argument, so you’d need 5 arguments, the player to fire the event to, and your tuple arguments, you gave it 4 for the FireClient, and it thinks plr1 is who to fire the event to and the other 3 to be the arguments to send, the 4th one is never entered, thus, it’s nil

Player 1 and 2 are the same person because I’m testing it. So what do I do?

Change this to this

trade.OnServerEvent:Connect(function(plr,plr1,plr2,items1,items2)

And this

trade:FireClient(plr1,plr2,items1,items2)

To this

trade:FireClient(plr,plr1,plr2,items1,items2)

The “plr” underlines red, what do I do then? In the Fire Client statement.

Wait how does your OnServerEvent look like right now?