Max/min or min/max?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    the ui to be the percent of score depended of the other team

  2. What is the issue? Include screenshots / videos if possible!


    blue has 1 point but the ui says he has 0

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    the other way / and that comment

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

red = game:GetService('Teams').Red.ScoreInt
blue = game:GetService('Teams').Blue.ScoreInt
while true do
	game:GetService('RunService').Heartbeat:Wait()
	red2 = red.Value
	blu2 = blue.Value
	
	local winPercentRed = math.clamp(math.max(red2,blu2)/math.min(red2,blu2),0,1)
	local winPercentBlue = 1-winPercentRed --math.clamp(blu2/red2,0,1)
	print(blu2,red2,'print',winPercentRed, winPercentBlue)
	if winPercentRed == winPercentRed and blu2~=red2 then
		UDimR = UDim2.fromScale(winPercentRed,1)
		UDimB = UDim2.fromScale(winPercentBlue,1) 
		script.Parent.Red.Size = UDimR
		script.Parent.Red.Text = 'Red: '..red2

		script.Parent.Blue.Size = UDimB
		script.Parent.Blue.Text = blu2..' :Blue'	
	else
		UDimR = UDim2.fromScale(0.5,1)
		UDimB = UDim2.fromScale(0.5,1) 
		script.Parent.Red.Size = UDimR
		script.Parent.Red.Text = 'Red: '..red2

		script.Parent.Blue.Size = UDimB
		script.Parent.Blue.Text = blu2..' :Blue'
	end
	
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

What if you remove the minus 1 from that line

i think that is not what i want
winPercentBlue is supposd to be the other half of winPercentRed
but i try
output= doesnt work

1 Like

By this do you mean something that shows how much the red has compared to the blue? Like the blue:red ratio?

If so, you don’t need math.min and math.max for this. What you need to do is add both scores to get the total number of points, then divide by this number to find the ratio of blue:red:

local red = 2
local blue = 1
local totalPoints = red + blue -- this will be 3 obviously
-- now, to get the percentage of red, we need to do red / totalPoints
local percentageRed = red / totalPoints -- 2/3, which would be 2 of the 3 available points
local percentageBlue = blue / totalPoints -- 1/3
-- now for sizing the UI,
local sizeRed = UDim2.fromScale(percentageRed, 1)
local sizeBlue = UDim2.fromScale(percentageBlue, 1)
2 Likes