How to have multiple enemies spawn at a certain chance?

Hello, I want to know how I could make a chances type of thing by spawning multiple enemies. I want to have it go from 1 - 6, 1 being common and 6 being the rarest, 2, 3, 4, and 5 ranging from that chance too.

How would I do this though, I am making a round - based game and I would want a message GUI pop up and say the amount that will spawn. I don’t know how I would do a chance sort of thing though.

The current project I am making is a quick survival game where you run from multiple enemies through multiple maps, I want the gameplay to be a little more interesting instead of just running away from 1 thing for the whole game.

How could I do this?

To Create a Random, Do this:

local RandomNumber = math.random(1,600) -- Essentially means 1 in 600 (Change it if you like)

However you if have a table of Mobs:

local Mob = {
Mob1 = script.Mob1;
Mob2 = script.Mob2;
Mob3 = script.Mob3;
Mob4 = script.Mob4;
Mob5 = script.Mob5;
Mob6 = script.Mob6;
}

local RandomMob = Mob[math.random(1, #Mob)]
--[[ This Gets the Table's child, but since we are going
through a random, it picks a random mob out of the table

]]

local Monster = RandomMob:Clone()
Monster.Parent = workspace
1 Like

I would look into this article: weighted-chance-system , make a table with the number and weights

1 Like

So I read it and wrote some code in a Module Script:

local eventTable = {
	['Event1'] = 0.8,
	['Event2'] = 0.65,
	['Event3'] = 0.45,
	['Event4'] = 0.3,
	['Event5'] = 0.25,
	['Event6'] = 0.1,
	
}

local Weight = 0

for _, Chance in pairs(eventTable) do
	Weight += (Chance * 10)
end

local ranNumber = math.random(1, Weight)

Weight = 0
for Prize, Chance in pairs(eventTable) do
	Weight += (Chance * 10)
	
	if Weight >= ranNumber then
		-- // ???
		break
	end
end

return eventTable

I don’t know what I would do once it is revealed, I don’t know how I would spawn the amount of events there are, also I don’t know how this would work since the round system repeats. I use the PivotTo function to Pivot the enemies to a parts position in a map.