Searching through a ModuleScript with a loop

Hello scripters of the Devforum,

I have been recently developing a Tank system and I ran into some issues im not exactly sure how to fix.
For context, my tank system allows adding guns to a compatible vehicle only by placing vital parts (muzzle part and aimpart) and by adding the new gun’s stats into a Gun config moduleScript. This would be done by a developer wanting to install more guns into their tank.

Now, im working on replacing the direct-raycast system currently installed with “FastCast” a module created by a DevForum user. The problem is that this script requires creating a “caster” for each gun and Im thinking the best solution is to somehow register every gun on every compatible vehicle and then create a Caster for each one. So the current problem is:
How can I use a loop to find how many guns there are in every vehicle?
Once I figure this out I can make the rest of the code.
The goal right now is to read the properties ( “n#Muzzle”) on the moduleScript and that tells me if theres a gun, or if it were “n3Muzzle” then its the third gun on that vehicle. How can I use a loop to read these values?

You use a normal for loop:
For Example:

local module = {
Gun1 = true,
Gun2 = false,
Gun3 = true,
}
for index, value in pairs(module) do
print(index) -> Gun1, Gun2, Gun3
print(value) -> true, false, true
end
1 Like