Sorting and changing tips

I want it so that when a parameter is received (which is a number) will determine how many “bars” will fill with color.

The idea is how much health someone has, looking something like this:

To get to that I have a code like this:

local function ChoiceClicked(Icon, InfoText, Category, Thinking, Stamina, Health)
	for i, v in pairs(infos:GetChildren()) do
		v.Visible = false
	end
	InfoText.Visible = true
	script.Parent.Icon.Image = Icon
	script.Parent.Category.Text = Category
	
	if Thinking == 2.5 then
		--blah blah blah
	elseif Thinking == 3 then
		-- a lot of unnecessary code
	end
end

script.Parent.Parent.ChoiceFrame.Agriculture.MouseButton1Click:Connect(function()
	ChoiceClicked(proffesionIcons["AgricultureIcon"], infos.AC_Text, "Agriculture", 3, 4, 5)
end)

So I was just wondering if there is a better way to do this, all tips are welcome.

If there is going to be a background like in the pic you showed, you can just make a regular progress bar with small black notches over it to make it look like bars:

image

The progress bar could then just be a green bar on top of a gray bar whose size scale is between 0 and 1 depending on how full the bar should be.

1 Like

Yes, but that would also take the same script, and I need a better alternative if there is one.

You can take the amount of health the player has, and divide it the max amount of health. Then divide that number by the amount of bars you have. You can use math.floor(dividedNum) to get the amount fo full bars. Fill those bars in completely. Then get the divided number and subtract it by the math.floor number. That will give you the amount of space you need to occupy in the next bar.

Ultimately, I used @azqjanna 's idea and scripted more lines of code with the if statements.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.