JartsGT
(JartsGT)
October 27, 2021, 12:39pm
#1
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
script.Parent.MouseButton1Click:Connect(function()
event:FireServer(weaponName)
script.Parent.ClickSound:Play()
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
end)
You cannot access server storage from a local script, use replicated storage or other methods.
1 Like
Zenqpa
(Cyberaxe)
October 27, 2021, 12:45pm
#3
Just add it in Rep_Storage, Server Storage cannot be accessed from the client (localScropt)
JartsGT
(JartsGT)
October 27, 2021, 2:20pm
#4
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.
JartsGT
(JartsGT)
October 27, 2021, 2:27pm
#7
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).
JartsGT
(JartsGT)
October 28, 2021, 12:14pm
#9
I forgot to mention that I fixed all the errors but thanks for the reply!