Percentage chance like auto rap battles?

Hey roblox!

After a couple of months of leaving roblox development and exploring elsewhere i’ve decided to return, I am wanting to create a game similar to rap battles though I have been stuck for a couple days on a percentage system for picking the “rapper”. I have tried the below although this seems cluttered and won’t easily allow access for round systems/monetisation. I have looked all over the internet and the most I can find is a really confusing and cluttered free model. If anyone could point me in the right direction of how i’d calculate/change percentages please let me know as I have a rough idea of actually picking the player once I have the percent! Thanks!

local percenthold = game.ReplicatedStorage.percent

function UpdatePoints()
	wait(.01)

	local total = 0

	for i,v in pairs(game.Players:GetPlayers()) do
		print(v.name .. "'s percent is "..v.percent.value)
		total += v.percent.value
	end

	print("Total is "..total)
	local newtotplus = total
	local newtotminu = total


	if(total > 100) then
		print("bigger than")
		while (newtotminu > 100) do
			wait(0.01)
			for i,v in pairs(game.Players:GetPlayers()) do
				if(newtotminu > 100) then
					newtotminu -= 1
					v.percent.Value -= 1
				end
			end
		end
	end

	if(total < 100) then
		print("smaller than")
		while(newtotplus < 100) do
			wait(0.01)
			for i,v in pairs(game.Players:GetPlayers()) do
				if(newtotplus < 100) then
					newtotplus += 1
					v.percent.Value += 1
				end
			end
		end
	end
end



game.Players.PlayerAdded:Connect(function(plr)
	PlayerAdded(plr)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	UpdatePoints()
end)


function PlayerAdded(plr)
	--- Give added player percentage holder
	local clone = percenthold:Clone()
	clone.Parent = plr
	clone.Value = 100 / #game.Players:GetPlayers()
	---
	
	wait(.01)

	local total = 0

	for i,v in pairs(game.Players:GetPlayers()) do
		print(v.name .. "'s percent is "..v.percent.value)
		total += v.percent.value
	end

	print("Total is "..total)
	local newtotplus = total
	local newtotminu = total


	if(total > 100) then
		print("bigger than")
		while (newtotminu > 100) do
			wait(0.01)
			for i,v in pairs(game.Players:GetPlayers()) do
				if(newtotminu > 100) then
					if(v.name ~= plr.name) then
					newtotminu -= 1
						v.percent.Value -= 1
						end
				end
			end
		end
	elseif(total < 100) then
		print("smaller than")
		while(newtotplus < 100) do
			wait(0.01)
			for i,v in pairs(game.Players:GetPlayers()) do
				if(newtotplus < 100) then
					newtotplus += 1
					v.percent.Value += 1
				end
			end
		end
	end
end

while true do
	wait(30)
	UpdatePoints()
end

(If this is the best way of doing it please also let me know so i can continue! :slight_smile: )

1 Like