Attempt to call a nil value

try
local function()
instead of just function.

(Not that it would change anything but just try)

yeah, it did nothing. same output lol

Where is the script located? Server Script Service?

It’s inside of StarterGUI.Gui.Frame

Ah I see now.

ServerScriptService.Script:3: attempt to index nil with 'WaitForChild' - Server - Script:3

The character is not loaded in fully when this script is called.

Also, you have another problem.
Infinite yield possible on 'Players.Crcoli737:WaitForChild("Knife")' - Studio
Try what @SOTR654 posted below.

Try this:

function setupButtons()
    for i, v in pairs(script.Parent:GetDescendants()) do
	    if v:IsA("TextButton") then
		    v.Activated:connect(function()
			    if v:IsDescendantOf(script.Parent.Skins) then
				    displayItem(v.Name, "knife")
			    end
		    	if v:IsDescendantOf(script.Parent.Abils) then
	    			displayItem(v.Name, "ability")
    			end
				if v:IsDescendantOf(script.Parent.Gears) then
				    displayItem(v.Name, "gear")
		    	end
			    if v:IsDescendantOf(script.Parent.RevolverSkins) then
				    displayItem(v.Name, "revolver")
			    end
		    end)
	    end
    end
end
setupButtons()

It’s shorter.

u sure? im not getting that error, its in a UI in startergui

Oh my bad. I put the Script in ServerScriptService, it tried to call the character before it was loaded in. So, try what @SOTR654 put above, it may work because it won’t index a nil value, unless there is another problem that I am unaware of.

1 Like

i’m still getting the code error, same error message

So let me get this straight, the function is throwing the error when it is trying to index the player?

I don’t know, i’m revamping an old friend’s code.

“Attempt to call a nil value” normally means you are trying to call a function that doesn’t exist. Did you make sure that the “Skins”, “Abils”, “Gears”, and “RevolverSkins” folders are where they should be?

1 Like

Ok… In the lines that say

for i, v in pairs(script.Parent:GetDescendants()) do

replace with

for _, v in pairs(script.Parent:GetDescendants()) do

I’ve seen some people do it this way, not to sure what exactly this does, but give it a try.

I’m pretty sure that’s just ignoring the index variable of the loop, cause we’re more or less getting the values of them so it wouldn’t make any difference I assume?

yup image

it did absolutely nothing lol.

Could you pcall it? I don’t know, if you can’t tell, I am running out of ideas.

What is a pcall and how do i do it

Well,

pcall stands for Protected Call, it is a type of function that is basically doing “sudo” in a Linux terminal, it is normally used for pulling and saving data to a datastore.

Topic on pcalls