Attempt to get length of a Instance value error

my script is located in serverscriptservice.

Code:

local items = game.ReplicatedStorage.Weapons

local wep1 = script.weapon1

local wep2 = script.weapon2

local wep3 = script.weapon3

local wep4 = script.weapon4

local wep5 = script.weapon5

local wep6 = script.weapon6

wep1.Value = items[math.random(6, #items)]

wep2.Value = items[math.random(6, #items)]

wep3.Value = items[math.random(6, #items)]

wep4.Value = items[math.random(6, #items)]

wep5.Value = items[math.random(6, #items)]

wep6.Value = items[math.random(6, #items)]
5 Likes

Get the table of children so do

local items = game.ReplicatedStorage.Weapons:GetChildren()

so that you get a table of the children, and then you can get the length of it.

Also not sure math.random(6, #items) was what you meant, perhaps just math.random(#items) since in your case it would always select the sixth weapon.

11 Likes

omg how could i glance over this.
not my brightest moment Thanks!

2 Likes