Help with fixing my weapon storage script

Hi devs, so recently my I asked my friend is he could write a script for me. But when I tested the script to see if it was working it has an error on line 68 when it said “ItemStorage” This is a folder I made for some weapons so that the script chooses a random weapon when clicked. So the I checked the folder and it said ItemStorage like I put it. I am very confused please help me.

2 Likes

this belongs in scripting-support . anyways you never made a variable called ItemFolder . put this in the first part of the script and it should work.

local ItemFolder = game.ReplicatedStorage.ItemStorage

1 Like

This helped but then this error occurred. How do I fix it? It says ItemStorage is not a valid member of ReplicatedStorage. It says the error is on line 25-26

1 Like

Why is the image stretched out like that LOL

You should include a WaitForChild() function, so that the code will yield until it can find that “ItemStorage” object inside the ReplicatedStorage

Also this needs to be in #help-and-feedback:scripting-support, please change the category

2 Likes

What you typed is a bit confusing since I did not write the script and my friend did lol.

The line where you define your ItemStorage variable, change that to

local ItemStorage = RP:WaitForChild("ItemStorage")
2 Likes

He means add a :WaitForChild(). This is a great oppurtunity to learn something about coding:

local RP = game:GetService("ReplicatedStorage") -- Identify Replicated Storage
local ItemStorage = RP.ItemStorage

This might error because “ItemStorage” may not be loaded in time. To fix this, we use the function “Wait For Child”. It essentially does what it says. It waits for the given item in quotations to be loaded.

What it should be:

local ItemStorage = RP:WaitForChild("ItemStorage")
2 Likes

Thanks! I learned something new from this which helped with this script!

2 Likes

No problem! I’m here to help :grin:

1 Like