Argument 1 missing or nil error when InvokeServer() is run

Hello! I have this error in my game: “Argument 1 missing or nil”. It has never appeared before, it only started yesterday. I’ve tried everything on the DevForum and everything I’ve looked at so far hasn’t applied to me. If someone could shed some light on what’s going on, I’d be very appreciative!

Here’s the server code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local events = ReplicatedStorage:WaitForChild("Events")
local abilities = ReplicatedStorage:WaitForChild("Abilities")

events.ShopEvent.OnServerInvoke = function(player, perk, price)
	if player then
		if player:FindFirstChild("Tokens") and player.Tokens.Value >= price then			
			player.Tokens.Value -= price
			
			if abilities:FindFirstChild(perk) and not player.abilities:FindFirstChild(perk.Name) then				
				local newAbility = abilities[perk]:Clone()
				newAbility.Parent = player.abilities
				
				return true
			else
				return false
			end
		else
			return false
		end	
	else
		return false
	end
end

The error seems to occur on line 12 which is this:

if abilities:FindFirstChild(perk) and not player.abilities:FindFirstChild(perk.Name) then

Here is the client code:

local purchaseSuccess = events.ShopEvent:InvokeServer(ability.Name, ability.Price.Value)

I dont see this variable named “abilities” defined anywhere, rename it to “player.abilities”.

Let me put the variables so it makes more sense:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local events = ReplicatedStorage:WaitForChild("Events")
local abilities = ReplicatedStorage:WaitForChild("Abilities")

Ohh let me check the code all together

player.abilities:FindFirstChild(perk.Name)

On the client, the “perk” variable is sent as a string. On the first comparation it was comparing a string, but for some reason this one is comparing as an Instance. Remove “.Name” from it and it should work fine (I think)

Okay, I’ll try that and see if it changes anything.

I tried it and it didn’t work, but it didn’t give me an error either which probably means that it returned false. Maybe because FindFirstChild only works with strings.

Thats good, now I can understand whats happening.

Try removing this line of code because we fixed the actual problem and now we need to get the “If” function return true

 and not player.abilities:FindFirstChild(perk)

The code is still not working.

Ok, my final idea is to put print() functions all around to debug, like this:

print("pass1")
print("pass2")
print("pass3")

It printed “pass1” and “pass2” but not “pass3”

Okay, I got it to work, I had to do perk.Name and boom it worked! Thanks for the printing idea!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.