Argument 2 missing or nil

I am trying to make an NPC give you a tool.

Script:

local classes = require(script.Parent.Classes)

local mps = game:GetService("MarketplaceService")

if classes.Economy == false then
	script.Parent.Dialog.CheckIn.Economy:Destroy()
end
if classes.PremiumEconomy == false then
	script.Parent.Dialog.CheckIn.PremiumEconomy:Destroy()
end
if classes.Business == false then
	script.Parent.Dialog.CheckIn.Business:Destroy()
end
if classes.Investor == false then
	script.Parent.Dialog.CheckIn.Investor:Destroy()
end

script.Parent.CheckIn.OnServerEvent:Connect(function(plr,class)
	if classes[class] == 0 then
		game:GetService("ServerStorage")(class.Name):Clone().Parent = plr.Backpack
	else
		if mps:UserOwnsGamePassAsync(plr.UserId,classes[class]) then
			game:GetService("ServerStorage")(class):Clone().Parent = plr.Backpack
		else
			mps:PromptGamePassPurchase(plr,classes[class])
		end
	end
end)

Classes (Module Script)

-- If a class is free, set it to 0. If the class is paid set it to the gamepass id. If you want to disable a class, set it to false.

local classes = {}

classes.Economy = 0
classes.PremiumEconomy = 0
classes.Business = 0
classes.Investor = 0

return classes

Localscript

local dialog = game.Workspace:WaitForChild("CheckIn NPC").Head.Dialog

dialog.DialogChoiceSelected:Connect(function(plr,choice)
	if choice == dialog.Economy then
		dialog.Parent.Parent.CheckIn:FireServer(game.Players.LocalPlayer,"Economy")
	elseif choice == dialog.Business then
		dialog.Parent.Parent.CheckIn:FireServer("Business")
	elseif choice == dialog.Investor then
		dialog.Parent.Parent.CheckIn:FireServer("Investor")
	elseif choice == dialog.PECO then
		dialog.Parent.Parent.CheckIn:FireServer("PremiumEconomy")
	end
end)

Explorer:

The Serverscript on line 22.

wordss

In your LocalScript, you can change it and remove the game.Players.LocalPlayer because RemoteEvents automatically pass the player who fired the remote to the server.

local dialog = game.Workspace:WaitForChild("CheckIn NPC").Head.Dialog

dialog.DialogChoiceSelected:Connect(function(plr,choice)
	if choice == dialog.Economy then
		dialog.Parent.Parent.CheckIn:FireServer("Economy")
	elseif choice == dialog.Business then
		dialog.Parent.Parent.CheckIn:FireServer("Business")
	elseif choice == dialog.Investor then
		dialog.Parent.Parent.CheckIn:FireServer("Investor")
	elseif choice == dialog.PECO then
		dialog.Parent.Parent.CheckIn:FireServer("PremiumEconomy")
	end
end)

Can u copy paste that line plz? Not on my pc rn

I tried that but then I got the error Argument 1 missing or nil

if mps:UserOwnsGamePassAsync(plr.UserId,classes[class]) then

Line 22 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

That’s… weird.

Try printing classes[class] before the if statement on line 22.

you used wrong brackets, its [class] no (class), so you can try this:

local classes = require(script.Parent.Classes)

local mps = game:GetService("MarketplaceService")

if classes.Economy == false then
	script.Parent.Dialog.CheckIn.Economy:Destroy()
end
if classes.PremiumEconomy == false then
	script.Parent.Dialog.CheckIn.PremiumEconomy:Destroy()
end
if classes.Business == false then
	script.Parent.Dialog.CheckIn.Business:Destroy()
end
if classes.Investor == false then
	script.Parent.Dialog.CheckIn.Investor:Destroy()
end

script.Parent.CheckIn.OnServerEvent:Connect(function(plr,class)
	if classes[class] == 0 then
		game:GetService("ServerStorage")[class]:Clone().Parent = plr.Backpack
	else
		if mps:UserOwnsGamePassAsync(plr.UserId,classes[class]) then
			game:GetService("ServerStorage")[class]:Clone().Parent = plr.Backpack
		else
			mps:PromptGamePassPurchase(plr,classes[class])
		end
	end
end)

Major oversight on my behalf, touché.

Althought the line that’s erroring (at least according to OP), isn’t that line.

I have already tried that it doesn’t work.

it must be:
mps:UserOwnsGamePassAsync(userID,gamepassID)
and gamepassID cant be 0, so you can add more values in your module script like this:

-- If a class is free, set it to 0. If the class is paid set it to the gamepass id. If you want to disable a class, set it to false.

local classes = {}

classes.Economy = 0
classes.PremiumEconomy = 0
classes.Business = 0
classes.Investor = 0

classes.EconomyGamepass = 8426083 
classes.PremiumEconomyGamepass = 234567
classes.BusinessGamepass = 345678
classes.InvestorGamepass = 456789

return classes
local classes = require(script.Parent.Classes)

local mps = game:GetService("MarketplaceService")

if classes.Economy == false then
	script.Parent.Dialog.CheckIn.Economy:Destroy()
end
if classes.PremiumEconomy == false then
	script.Parent.Dialog.CheckIn.PremiumEconomy:Destroy()
end
if classes.Business == false then
	script.Parent.Dialog.CheckIn.Business:Destroy()
end
if classes.Investor == false then
	script.Parent.Dialog.CheckIn.Investor:Destroy()
end

script.Parent.CheckIn.OnServerEvent:Connect(function(plr,class)
	if classes[class] == 0 then
		game:GetService("ServerStorage")[class]:Clone().Parent = plr.Backpack
	else
		print(plr,classes[class.."Gamepass"])
		if mps:UserOwnsGamePassAsync(plr.UserId, classes[class.."Gamepass"]) then
			game:GetService("ServerStorage")[class]:Clone().Parent = plr.Backpack
		else
			mps:PromptGamePassPurchase(plr,classes[class.."Gamepass"])
		end
	end
end)

I made it check if the gamepassId is 0, and if it is it makes it free. :slightly_smiling_face:

@Imaginalities I tried what you said and it stopped the errors but still didnt work.

???

My solution was incorrect, I thought class was an instance but it was actually a string, you use class.Name in an earlier line so I thought it was an instance.

And it should have errored because it’s still nil

I’m really confused. Btw you are way too inconsistent, sometimes you do (class) other times you do [class]. The 2 marketplace service calls, one uses plr.userid the other uses plr

gamepassID is LOCATION of game pass, example: https: //www.roblox.com/game-pass/0123456/Slime-Shield
ID is = 0123456

Roblox it literally said, argument 2 is nil, because he cant found it

I made it so if it is 0 it is free so why would it prompt someone to buy gamepass 0. :confused:

“if classes[class] == 0 then
game:GetService(“ServerStorage”)[class]:Clone().Parent = plr.Backpack”

yes this is right, but you cant use classes[class] in gamepassID

mps:UserOwnsGamePassAsync(userID,gamepassID)