How come this only spawns one item?

local randomPartsFolder = game.Workspace.ItemSpawns:GetChildren()

local RandomObjects = game.ServerStorage.Items:GetChildren()

wait(5)

local function randomSpawn()

local pos = randomPartsFolder[math.random(2, #randomPartsFolder)]

local randomClones = RandomObjects[math.random(2, #RandomObjects)] -- This is the 
one I need help with. It only spawns one item

randomClones.Position = pos.Position

randomClones.Parent = workspace

print(randomClones.Name)

end
randomSpawn()

Yeah, it only spawns one thing out of the 4 things in the folder.

2 Likes

It only spawns one item because you are only selecting one item. If you want it to spawn multiple things, put randomSpawn() into a for loop.

Also, I would suggest using Roblox’s Random object instead of math.random for “more reliable” random numbers, I guess you could say.

3 Likes

You need to loop this, or use an event, and just get it to fire an event the number of tools wanted. Hope this helped!

Yeah, I did that right after I posted. Also I’ll probably switch to using the Random object thing. Thanks for the help

An event would be bad to do something like this, as exploiters can just fire it repeatedly. Also I found the solution, thanks though!

Oh OK, thanks for letting me know!

I think they use the same generator, the Random object just has prettier syntax. Edit: You can have multiple Random objects while you can only ever use math.random. They’re fairly different, but the actual numbers themselves aren’t more reliable.

Based on:

2 Likes

math.random and the Random API use the same algorithm but I think it may be more than just pretty syntax? Random is an object with methods based around it, while math.random is a function and any modifiers are independent of it (such as using math.randomseed).

math.randomseed(tick()) -- Change seed relative to environment
math.random()

-- vs

Random.new(tick()) -- Change seed relative to object
Random:Next[Number/Integer] -- Get a direct number, no after-math (pun unintended)
3 Likes

Yeah, Random is pretty different, but the numbers aren’t really more reliable like unrect said.

3 Likes

For sure. I don’t know what “numeric reliability” is between Random and math.random. That’s unimportant, it’s a random number generator. There is no such thing as reliability between either method. Me personally though, I prefer Random mainly because

A. I don’t want to do extra math; I just want my number as in when I call it.
B. Seed relativity.
C. Branching.

2 Likes