Argument 2 is missing or nil

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    IM trying to make a system that loops through each badge and if they have said badge it sets its corresponding value to true
  2. What is the issue? Include screenshots / videos if possible!
    on the badge check it is saying argument 2 is nil or missing (badge id is argument 2
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

i know it has something to do with that I’m not using a number but i have a list of numbers earlier in the script where i give each badge ID a name that matches to the bool value name
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

game.Players.PlayerAdded:Connect(function(player)
	local OSVcp = OSV:Clone() --this really isnt important its just cloneing the values 
	OSVcp.Parent = player
	OSVcp.Name = (player.Name .. "Ownerships")
	wait()
	for i, v in pairs(OSVcp:GetChildren()) do
		if badgeservice:UserHasBadgeAsync(player.UserId,tonumber(v.Name)) then -- heres the error part
			v.Value = true
			print("user has a plush")
		elseif not badgeservice:UserHasBadgeAsync(player.UserId, tonumber(v.Name)) or v.Name == nil then
			v.Value = false
			print("user doesnt have a plush")
		end
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Hey there,

A few notes:

1.Use task.wait instead of wait [it’s more efficient and accurate]
2.What is OSVcp?
3.instead of this line if badgeservice:UserHasBadgeAsync(player.UserId,tonumber(v.Name)) then
you could do:

local badges = game:GetService("BadgeService")
local userHasBadge = badges.UserHasBadgeAsync
local awardBadge = badges.AwardBadge
local badgeId = 0000000 --adjust it

local success, result = pcall(userHasBadge, badges, player.UserId, badgeId) --HasAsync,Service,userID,badgeID
	if success then
         if not result then
            v.Value = false
			print("user doesnt have a plush")
         else
           v.Value = true
		   print("user has a plush")
         end
    end
end)

OSVcp is the folder containing all of the bool values

And their names represent gamepass ID’s?

The names each have their own corresponding gamepass but their names arent the IDs

The second argument in “UserHasBadgeAsync” has to be a number, particularly the ID of the badge.
You need to make sure v indeed represents the ID. I assume you have more values there that some of them might not be numbers/ID’s.

Adding on to this, badgeID is 8 integers!
(Or 16777216 different unique badges)

1 Like