What do you want to achieve?
I want to be able to give weapons attachments, which would be able to do during run time and on spawn.
What is the issue?
While I don’t have any problems with the visuals, the issue comes from changing weapon stats, which I am unsure of how to do. My current weapon system uses a module script to hold the stats and then saves them locally on the script like this:
local gunStat = GunStats.Stat
What solutions have you tried so far?
I tried looking for solutions on the forums, but I couldn’t find anything
Make a table storing all of the stats that can be changed through attachments and require the modules of the attachments updating the table, then just multiply the base stats with the stats in the table.
A bit confused by what you’re trying to say, so I’ll try to explain how my current idea for attachments looks.
Basically, each attachment has a module in it that just lists different stats that a weapon has, so by requiring the attachment module I basically get a list of the attachment stats. Then I could apply the given stats to the weapon’s stat module, but the problem comes from the fact that the stats don’t change, which is where my issue of not knowing how to change the stats comes from.
EDIT: More specifically they don’t change ON THE CLIENT
You change the stats by multiplying the base stat with the attachment stat
for example
local ModTable = {
Recoil = 1,
}
-- you then require the attachment module which would update the recoil
ModTable.Recoil = attachmentMod.Recoil
-- and then when its time to make the recoil happen, simply multiply
recoilAmount = gunStats.Recoil * ModTable.Recoil
After a bit of tinkering I came to a solution of this:
Since I have both a server and a client script in the gun, I just use the server script to change the values server sided and the client script client sided and I this is how my gun is set up: