Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how can I make math.random select more than 1 random thing?

I need to know how to do this because in my new game project math.random only selects 1 player to be the criminal.

here is an example of what I have to make it select 1 person.

criminals = people[math.random(1, #people)]

1 answer

✓ Accepted answer

The reason is for that theres only 1 player selected is because your using

math.random(1,  #people)

The '1' makes it only select one player.

I suggest using a table.

Much easyer to use. Example code :

criminals = {}

for i = 1, math.random(1, 5), 1 do

	while wait() do
		local NC = people[math.random(1, #people)]
		for _,plr in next,criminals do
			if plr ~= NC then
				table.insert(criminals, NC)
				break -- Stop the while loop
			end
		end
	end

end

So now what you can do is much MUCH more simple,

Example

for _,plr in next,criminals do
	local Character = workspace:WaitForChild(plr.Name)
	local Human = Character:WaitForChild("Humanoid")
	Humanoid.Died:connect(function()
		print(Character.Name..", died")
	end)
end

1 comment

0
  1. "The '1' makes it only select 1 player" is false; the '1' just says "return a random number with value at least 1". 2. Your inner loop doesn't work: it will always add the criminal, regardless of whether they're in the table of criminals or not. 3. I recommend using "#people/2", not "math.random(1,5)" - what if there are only 4 players, for instance?

This discussion is preserved as it was. New answers, comments, and votes are closed.