How To Make A More Efficient Loadout System

So the module below contains a dictionary of weapon names and the function within the module checks the parameter “item” name and if it matches with the ones in the table it will take the clone of the weapon and put it into the player’s backpack.

Only thing I’m not satisfied with is how inefficient this feels, every time I make a new weapon I have to go back into the module and create a new if statement for the new weapon.

I’d like to know a more efficient way of doing this, code below.

modulereview.rbxl (43.3 KB)

3 Likes

You could have each loadout be a table of instances that need to be cloned into the player’s backpack. That way you do not have to have a different check for every new weapon, anything in the table is part of the loadout. Using a table also has the advantage that you can convert it to/from a string (using HttpServcice JSONEncode) which you can then save/load to a datastore.

1 Like

Could you provide an example please?

1 Like
myLoadout = {WeaponsFolder.Pistol, UtilityFolder.HealPack}

Then to equip this loadout you just need to clone each thing from the list.

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