Get # Of assests

Of I’m trying to get the number of assets in game and do calculations but for some reason it gives me an error: “invalid argument #2 to ‘random’ (interval is empty)” when I print assets it prints a table but in my code I put # before assets so why wont it work?
local assests = workspace:GetChildren()

print(assests)

local s = math.random(100, #assests - 100)

local t = s + math.random(50,300)

local n = math.random(100, #assests - 100)

Try to print #assests and see how many you’ve got there.
Also try this :

local assests = workspace:GetChildren()
print(#assests) -- what does it print?

local s = math.random(100, #assests)
local t = s + math.random(50,300)
local n = math.random(100, #assests)

I talked about #assets, not the table itself.

I already said I tried lol
image

it gives 148 so it does work so why not with this?

Notice that there is a difference between print(assets) and print(#assets).

Yes ik I didnt see the # in your message

local assests = workspace:GetChildren()
print(#assests) -- what does it print?

local s = math.random(100, #assests)
local t = s + math.random(50,300)
local n = math.random(100, #assests)

print(s,t,n) -- prints?

Does this code work to you?

(Also a side note for general :
the second argument in math.random has to be greated than the first one)

I think I know whats wrong thanks for your help anyways :slight_smile:

1 Like

You likely need to add 100 not subtract 100 from the array’s length.

2 Likes