Tips for making a weapon modification system

I want to make a simple weapon modding system, sort of like how it is done in Apocalypse Rising Two, where you simply just select an attachment (like a Holosight) and drag it onto the gun. I don’t want to make it exactly like this, I just want to have an attachment put on a gun.

I use my own edit of thienbao2109’s FE Gun kit, meaning that the weapons are tools. I’m not sure how to go about adding attachments, as the only way I’ve thought of so far could be laggy from what I’m aware.

I have tried to do it like making attachments on the weapon, making them transparent and then making them visible when equipped, but I found this way VERY tedious hence I deleted it completely.

If you have any better methods please reply!

8 Likes

Im making an fps system right now actually. How most games do their attachment systems are by 2 points, one thats on the gun, and the other thats on the attachment

image
image
And for the sight
image
image

Edit: Basically you want to put the sight attachment onto the gun attachment

Then you could do

AttachmentBase.CFrame = (AttachPointOnGun.WorldCFrame * AttachmentBase.AttachmentPosition.CFrame:Inverse())

and it positions the EOTech right on the gun!
image

(same attachments on different gun)
image

15 Likes

Hi. Thank you very much for teaching me! This’ll get a lot of use now and I’ve been looking for a way for ages!

Good luck with your system, and thanks again for telling me how to do attachments. :smiley:

3 Likes

Hey, where do you put the script below?

AttachmentBase.CFrame = (AttachPointOnGun.WorldCFrame * AttachmentBase.AttachmentPosition.CFrame:Inverse())

2 Likes

you can put it in a serverscript connected to a remote event

1 Like

sorry for reviving the topic,

i have a game where players have a gui to select attachments, when an attachment is selected script reads some values etc. and then uses a module to attach the attachment, but if i attach 2 different types of attachments (like scope + supressor) the one thats added later just breaks and spawns far away. heres the source file to my place;

games.rbxl (269.0 KB)

how can i fix it? i tried multiple solutions thats why the scripts uses more values than they should do, can someone try to fix it or maybe tell me some ways to do it please? i was really hoping that i would be able to make a good attachment system, i solved many bugs and now im stuck here, i tried using WorldCFrame, CFrame, Position, Parenting the attachment to attacpart, parenting the attachment to parent of attacpart… and some more solutions

please help me!

(it doesnt use :Inverse() at the first source file but it originally does;
cfar.rbxl (269.1 KB)

1 Like

Hi, no problem, for future reference please don’t post your entire game to the devforum. I’m just helping because you’ve got a super specialized issue and have spent hours figuring it out (I know the pain :stuck_out_tongue:)

By what I can see your problem isn’t an issue with my code, its just a quirk to how weld constraints work.
(you do want to use :Inverse() as if you don’t your attachments will be placed backwards lol)

Here’s the attachment function in question. Note that you are instancing the weldconstraint and properly welding it before you position your attachment.

When your attachment is cloned, its essentially placed randomly in the world, when you weld the attachment to your attpart, it makes an unbreakable bond where if you move the attpart or the attachment then it will move the other part sometimes the attpart

To understand the issue further i’ve drawn up a few small sketches
the red dot is your attpart, the green dot is your suppressor mount attachment

This is after you weld, but before you position your attachment
image

Then once you position your attachment, because the attpart is welded to the suppressor it will move.

This is after the attachment is positioned
image

Now imagine you try to add another suppressor, or a sight, because the attpart isn’t in its correct position, it will “break”

Ok, we understand the problem, now how do you fix it? Quite simply, you literally just weld the attachment to the attpart after positioning it.

Aaaaand shabinga! Now you can put your aimpoint and camo suppressor on your gun!
image

6 Likes

someone fixed this by using another function, but now with your help i know why was that problem occuring, thanks for detailed explainatory

1 Like