Attempt to index nil with "FindFirstChild"

I’m trying to make an inventory and I’m almost done with it but I keep getting an error saying “Attempt to index nil with FindFirstChild”

the line with the error is:

local damage = weapon:FindFirstChild("Damage")

The error happens because the “weapon” is nil, but I have no clue how to make it not nil (the object in the serverstorage is a tool)

local weaponName = script.Parent.Parent.Name

	local serverStorage = game:GetService("ServerStorage")
	local weapon = serverStorage:FindFirstChild(weaponName)
	local damage = weapon:FindFirstChild("Damage")
	local cooldown = weapon:FindFirstChild("Cooldown")
	local parent = script.Parent.Parent.Parent.Parent
	parent.EquippedItemImage.Image = script.Parent.ItemImage.Image
	parent.EquippedItemName.Text = script.Parent.Parent.Name
	parent.EquippedItemDamage.Text = ""..damage.Value
	parent.EquippedItemSlashCooldown.Text = ""..cooldown.Value

You cannot access server storage from a local script, use replicated storage or other methods.

1 Like

Just add it in Rep_Storage, Server Storage cannot be accessed from the client (localScropt)

Well, now it works perfectly fine but it still keeps giving me the error?

Try running it in-game or making a server in the roblox studio test tab.

I have a template button in the inventory already with the same script, that one doesnt give errors but the cloned one does.

This just means that local weapon = serverStorage:FindFirstChild(weaponName) isn’t fetching any instance and is in fact returning nil. Make sure the script is in the right location. Put the weapon in Lighting or ReplicatedStorage or some other folder local scripts can access (make sure you change the reference inside the script).

I forgot to mention that I fixed all the errors but thanks for the reply!