How do i find the cheapest price?

i have multiple folders that i want to look through to check the price and print the lowest price a.k.a the attribute for every pad

local function findcheapestpad(tycoon)
	local minvalue = math.huge
	
	for _, pad in tycoon:FindFirstChild("Pads"):GetChildren() do
		if pad:GetAttribute("Price") < minvalue then
			minvalue = pad:GetAttribute("Price")
		end
	end
	
	for _, pad in tycoon:FindFirstChild("BoughtItems"):GetChildren() do
		if pad:HasTag("Pad") then
			print(pad)
			if pad:GetAttribute("Price") < minvalue then
				minvalue = pad:GetAttribute("Price")
			end
		end
	end
	
	return minvalue
end

I have tried doing this but after getting to the builds folder it just returns inf

Are you sure “pad” has the price attribute or not or the “Pad” tag?

okay it works now thanks for helping i figured it out

local function findcheapestpad(tycoon)
	local minvalue = math.huge
	
	for _, pad in tycoon:FindFirstChild("Pads"):GetChildren() do
		if pad:GetAttribute("Price") < minvalue then
			minvalue = pad:GetAttribute("Price")
		end
	end
	
	for _, build in tycoon:FindFirstChild("BoughtItems"):GetChildren() do
		for _, pad in build:GetChildren() do
			if pad:HasTag("Pad") then
				print(pad)
				if pad:GetAttribute("Price") < minvalue then
					minvalue = pad:GetAttribute("Price")
				end
			end
		end
	end
	
	return minvalue
end

i just had to make another for loop

another question though should i break the loop? i never break loops if i’m being honest :grin:

Oh so it didn’t in-fact exist okay… And no, no need to break loops. Unless you are going to call them every 60 seconds and the loop is big.

okay i remember seeing someone break a loop if something is nil i assume to avoid errors

Yeah but no need for this one.

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