How do you get the number value from In Pairs

I was wonder how do you get the value of the number like I am trying to get the total number of the wheels by using InPairs and I want to do it.

Program,

function AxleSensor(Vehicle)
	local Wheels = {}
	for i, v in pairs(Vehicle.Parent.Core:GetChildren()) do
		if v.Name == "Wheel" then
			table.insert(Wheels,v)
		end
	end
	if Vehicle.Parent:FindFirstChild("Trailer")then
		for i, v in pairs(Vehicle.Trailer:GetChildren()) do
			if v.Name == "Wheel" then
				table.insert(Wheels,v)
			end
		end
	end 
	script.TotalAxles.Value = Wheels
	print(script.TotalAxles.Value)
end

To find the total amount of items in a table, put a # before the table. This will return the number value of the amount of items inside the table. Since you are trying to combine two, use the plus operator.

local Wheels = #Vehicle.Parent.Core:GetChildren()+#Vehicle.Trailer:GetChildren()
1 Like

print(#Wheels) or just add them to a number yourself, and count with each one you add.

Edit: With the above post, this gives you a few options and depends on your needs.

2 Likes