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

How do you make a randomizing system like in Murder games?

You know that in Murder games, there are usually chances of being the murderer. This number changes for every person in the game.

For example, a server has 3 people, the first one gets 50% chance and the other 2 will get 25% chance. And in bigger server, the numbers would be much more complicated than that.

But you can't just do that normally with math.random, it's a very complex system, but it would turns out very well in games. So how do you make it?

6 comments

0

math

0

maffs?

0

But only when they are equal. If one chance is greater than the other, you must also handle that; in your system greatest values are in negative form.

0

Not sure what I was even saying, you don't need to randomly sort at all. This would work, I'm not sure what you're getting at. 5% of the time, a random integer generated between 1 and 100 will be 25-30, the same chance for it to be 30-35, et cetera.

0

You do not understand, the RandomPercentage is not the issue. It is a simple line of code. When you assemble bits & pieces together you make something entirely new.

0

You're not making any sense. Once the random percentage is <= 0 the chance is the one we want to select.

1 answer

✓ Accepted answer

We could use a table of players and chances for this:

local MurdererChances = {
	[Player1] = 60,
	[Player2] = 35,
	[Player3] = 5
}

local RandomChance = math.random(1, 100)
local Murderer = nil

for Player, Chance in pairs(MurdererChances) do
	RandomChance = RandomChance - Chance

	if RandomChance <= 0 then
		Murderer = Player
		break
	end
end

As has been pointed out this is a basic solution to the problem, and does not include the changing of chances as a game progresses.

1 comment

0

Very well

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