"1 is not a valid member of Folder "ServerStorage.Weapons.Bloxers""

effectively a part 2 to this…

so I have gamemodes working… kinda. now I need to get weapons. but for some reason it’s trying to find a number rather than an object within the weapons folder. my code:

weaponofchoice = game:GetService("ServerStorage").Weapons.Bloxers
local weapon = weaponofchoice[math.random(1, #weaponofchoice:GetChildren())]

obviously leaving out some details that I don’t think is necessary for this part of the script, but let me know if you do need it to figure it out. please help

1 Like

The reason it’s trying to find a number is because you’re feeding it a number as an argument, no?

If you do something like:

weaponofchoice = game:GetService("ServerStorage").Weapons.Bloxers:GetChildren()
local weapon = weaponofchoice[math.random(1, #weaponofchoice:GetChildren())]

This would work just fine because you’re choosing a random number and getting an index from a table instead of looking for something named a random number.

2 Likes

That is correct I misinterpreted in my head

2 Likes
weaponofchoice = game:GetService("ServerStorage").Weapons.Bloxers
local weapon = weaponofchoice:GetChildren()[math.random(1, #weaponofchoice:GetChildren())].Name

Or you can just write on a new line

weapon.Name ...-- further script

A line without a “.Name” just outputs a random number of object in a folder, but without its name. And you can also change

[math.random(1,#weaponof...

to

[math.random(#weaponof...

a little, of course, but still reduces

2 Likes