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

I need some help with a random percentage formula? [SOLVED]

I am working on a game where you by default have a (100 / NumberOfPlayersIngame) chance to get the special character. (Very similar to Murder Mystery)

The point where I am having trouble is you can purchase a thing called "Double Chance".

This means that if you have double chance and there are 5 people in the game then the formula would be (100 / NumberOfPlayersIngame) * 2 and then the difference would be split among the others.

What if 2 people bought the double gamepass, or 3 people. This is where I get extremely lost and I need your help.

If 2 people bought it then what would the formula be? What if 3 people bought the double gamepass?

Thank you for your time and hopefully someone can help me out. I have been working on this for a couple hours and cant figure it out.

2 comments

0

(100 / NumberOfPlayersIngame) * 2 * NumberOfPeopleWithPass

0

Hmmmmmmmmmmmmm. Like if two people had double chance on four player server, then the other players would have no chance, since the double chance people both have 50 chance.

2 answers

You could use what like animations use. Maybe each player has a weight of 10 to have the special role, and therefore someone with the gamepass has a weight of 20. You then add up all of the weights and generate a number like math.random(1, weightsum). Then lets say we have 3 players. Player one has the gamepass but the rest don't. Player1 would be murder with values 1 - 20, Player 2 would be murder with values 21-30, and Player3 would be murderer with values 31-40.

Or lets say that Player3 also has the gamepass. Then Player1 would be numbers 1-20, Player2 would be values 21-30, and Player3 would be values 31-50.

I was able to find a simple solution by basically putting names in a table, if they have double chance then there name gets put in twice.

	local TableOfPlayers = {}
	for Index, Object in ipairs(Players:GetChildren()) do
		table.insert(TableOfPlayers, Object)
		if DataFolder[Object.UserId].HasDoubleChance == true then
			table.insert(TableOfPlayers, Object)
		end
	end
	
	local ChosenAuntie = TableOfPlayers[math.random(1, #TableOfPlayers)]

1 comment

1

Never thought of that. Good way to do it, if not best.

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