Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Argument 1 missing or nil when using FindFirstChild?

I'm trying to make it so that when a value is greater or equal to a price (which is a value shown in line 12) it will print("green")

I get the error

20:53:58.844 - Argument 1 missing or nil 20:53:58.846 - Script 'Workspace.Tycoon.Tycoons.SampleTycoon.Buttons.Buy Drill - $50.Head.Script', Line 6 20:53:58.847 - Stack End

when i run it. Here's my script

repeat wait() until script.Parent.Parent.Parent.Parent:FindFirstChild("Owner") ~= nil
local name = script.Parent.Parent.Parent.Parent.Owner.Value
print("owner found")
repeat wait() until game.ServerStorage.MoneyStorage ~= nil
print("money found")
repeat wait() until game.ServerStorage.MoneyStorage:FindFirstChild(name) == true
while true do
	wait()
	if script.Parent.Parent.Parent.Parent.Owner.Value ~= "" then
		local name = script.Parent.Parent.Parent.Parent.Owner.Value
	    local money = game.ServerStorage.MoneyStorage:FindFirstChild(name)
		if game.ServerStorage.MoneyStorage(name).Value >= script.Parent.Parent.Price.Value then
			print("green")
		end
	end
end

Thank you

Edit: Also if it helps, so basically i have this script which is in this model, there a value in the model and it changes its value according to who owns the model. I need it so that the script takes that name of the person and goes to the serverstorage and looks for his name, the model is in the workspace but the money storage which i'm trying to get to is in serverstorage. Ex: i own the model. game.ServerStorage.MoneyStorage.DanThDev but i need it to work for everyone, i tried to do something like game.ServerStorage.MoneyStorage:FindFirstChild(name) but i'm getting that error and yea. Hopes this helps answer this.

2 answers

I believe the problem is that the script is looking for the value 'true' inside the search. But the object is not 'true', it simply exists, and therefore, is not nil.

To fix this:

repeat wait() until game.ServerStorage.MoneyStorage:FindFirstChild(name)

-- or

repeat wait() until game.ServerStorage.MoneyStorage:FindFirstChild(name) ~= nil

The problem is that name is nil, or a blank string. Make sure you check that neither of those conditions are true before proceeding with the rest of your code.

I also spotted another problem which you won't have reached yet. game.ServerStorage.MoneyStorage(name).Value
should probably be something like game.ServerStorage.MoneyStorage[name].Value
Reason being that I thik you wanted an index rather than a function call.

This discussion is preserved as it was. New answers, comments, and votes are closed.