How can i make a script that makes frames visible as a value increases?

i am currently trying to make an rpm bar on a dashboard, and I want the bar to scale with the rpm. the method i have right now is really messy and takes up unnecessary code, plus it is very tedious. is there a better way to do this?

function rpmChange()
	if carstatus.Value then
		local rpmBar = sc.G.RPMGauge.RPM
		
		sc.G.RPMV.Text = tostring(math.floor(rpm.Value))
		
		if math.floor(rpm.Value) >= 500 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end
		elseif math.floor(rpm.Value) >= 1000 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end
		elseif math.floor(rpm.Value) >= 1500 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end
		elseif math.floor(rpm.Value) >= 2000 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 2500 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end
		elseif math.floor(rpm.Value) >= 3000 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end
		elseif math.floor(rpm.Value) >= 3500 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end
		elseif math.floor(rpm.Value) >= 4000 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 4250 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end				
		elseif math.floor(rpm.Value) >= 4500 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 4750 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end
		elseif math.floor(rpm.Value) >= 5000 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 5250 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end
		elseif math.floor(rpm.Value) >= 5500 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end
		elseif math.floor(rpm.Value) >= 5750 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 6000 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end
		elseif math.floor(rpm.Value) >= 6250 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 6500 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 6750 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 7000 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 7250 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" or v.Name == "R21" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 7500 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" or v.Name == "R21" or v.Name == "R22" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end
		elseif math.floor(rpm.Value) >= 7750 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" or v.Name == "R21" or v.Name == "R22" or v.Name == "R23" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 8000 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" or v.Name == "R21" or v.Name == "R22" or v.Name == "R23" or v.Name == "R24" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 8250 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" or v.Name == "R21" or v.Name == "R22" or v.Name == "R23" or v.Name == "R24" or v.Name == "R25" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end	
		elseif math.floor(rpm.Value) >= 8500 then
			for i, v in pairs(rpmBar:GetChildren()) do
				if v.Name == "R1" or v.Name == "R2" or v.Name == "R3" or v.Name == "R4" or v.Name == "R5" or v.Name == "R6" or v.Name == "R7" or v.Name == "R8" or v.Name == "R9" or v.Name == "R10" or v.Name == "R11" or v.Name == "R12" or v.Name == "R13" or v.Name == "R14" or v.Name == "R15" or v.Name == "R16" or v.Name == "R17" or v.Name == "R18" or v.Name == "R19" or v.Name == "R20" or v.Name == "R21" or v.Name == "R22" or v.Name == "R23" or v.Name == "R24" or v.Name == "R25" or v.Name == "R26" then
					v.Visible = true 
				else
					v.Visible = false	
				end
			end				
		end
	end
end
1 Like

Could you be a little more clear? In your title you stated you wanted to make frames visible as value increases, yet you want a bar to scale with the rpm. Are these two issues that need to be solved?

P.S I’m a huge fan :blush:

1 Like

sorry for the misunderstanding, i have a bunch of frames that make up a circle, and i need them to become visible as a value is increased, in my case the rpm
image

response: i didn’t know i had fans, this is a first :blush:

So I’m assuming you either;
a) Want the colors to change as the rpm increases goes,
b) Want something complex to appear as the rpm increases.

This should help you

Edit: I assume you know how to get the decimel but its just currentvalue/maxvalue

its more like more frames become visible as rpm increases

i have a circular frame already, I have seen that and will use it in future projects!

Well, this does pretty much the same thing, just upload the sprite sheet(s) it gives you and input the decimals. The module automatically sizes it for you

Edit: this makes it easier, better looking, and more optimized than manually make frames and the like invisible and visible

Btw, you would just upload the actual progress part (In full state) with a transparent background and put it inside the rest of the gui.

Also since it’s a half circle and not a full circle. divide the decimal by two and have the correct rotation

i see. i really want to stick with the circle that i have right now, but i should probably give spritesheets a go

1 Like
local RPMZ = {{4000,11}, {6000,19}}


local BestChoice = {0,0}
for i,v in pairs(RPMZ) do
	if math.floor(RPM) >= v[1] and v[1] >= BestChoice[1] then
		BestChoice = v
	end
end

local Names = {}
for x = 1, BestChoice[2] do
	table.insert(Names, "R"..x)
end
for c,p in pairs(rpmBar:GetChildren()) do
	local IsInTable = false
	for i,v in pairs(Names) do
		if p.Name == v then
			IsInTable = true
		end
	end
	if IsInTable then
		p.Visible = true
	else
		p.Visible = false
	end
end

Just saying that it would be a lot easier, manually make frames visible and invisible is finicky and hard, you probably have to individually label each one, and multiply the amount of segments by the decimal, and go through each comparing its name to the previously mentioned number, and if its under or equal to it make it visible and if not make it invisible.

Keep in mind you would be doing this at least a few times a second.

You pasted code with no explanation, could you tell us what it does? Plus it doesnt look like it accounts for if the lower the index the lower the value of the segment is.

I dont undersand what the BestChoice variable is supposed to be though. the rest is understandable

After reading the code, it looks like you’re still manually mapping out everything, but for each possible rpm value with the number of segments.

BestChoice is the best matching RPM Table for what the current RPM is, once that is found it takes it and creates a table with R1, R2 all the way up to BestChoice[2], then with that it checks all the frames and if the name of the frame is in the table it will make it visible

so i would add all of the rpm values to the RPMZ table?

yes, if you want R1 up to R10 to visible at RPM 1000 you would add {1000, 10}
local RPMZ = {{1000, 10}, {2000, 20}}

Its more of a concept that I thought of that you may be able to get working

i see. thank you for the help!

I dont wanna be the bringer of bad news or whatever, but instead of manually mapping out 3 different things, (rpm, number of segments, and segment names), you could only have to edit the names and have an accurate rpm while only having to change the name of each segment. This seems less time consuming in my opinion.

(See my post above)