Hello! I’m currently trying to make an attachments system for FE Viewmodel, and it works with tools, here’s the code I’m using to attach attachments to the tool:
local AttachmentsModule = {}
local attachments = game.ReplicatedStorage.Miscs.Attachments
function AttachmentsModule.GiveAttachment(gun,attachment,player)
local newAttachment = attachment:Clone()
newAttachment.Parent = gun
local attachmentBase = newAttachment.AttachmentBase
local attachmentType = newAttachment.AttachmentInfo.AttachmentType.Value
newAttachment.Name = attachmentType.."Attachment"
local attachPointOnGun = gun.Handle:FindFirstChild(attachmentType.."Attachment")
attachmentBase.CFrame = (attachPointOnGun.WorldCFrame * attachmentBase.AttachmentPosition.CFrame:Inverse())
local weld = Instance.new("WeldConstraint")
weld.Parent = attachmentBase
weld.Part0 = gun.Handle
weld.Part1 = attachmentBase
--Stat code is skipped
script.ViewmodelAttachment:FireClient(player,gun,attachment)
end
This works fine, but whenever the viewmodel attachment remote event is fired from any script i’ve tested so far, and the gun is referenced in the local script, this happens:

Here’s my localscript handling viewmodel attachments:
script.Parent.ViewmodelAttachment.OnClientEvent:Connect(function(gun,attachment)
gun.Equipped:Wait()
local viewmodel = game.Workspace.CurrentCamera.ViewmodelStorage[gun.Name]
local newAttachment = attachment:Clone()
newAttachment.Parent = viewmodel
local attachmentBase = newAttachment.AttachmentBase
local attachmentType = newAttachment.AttachmentInfo.AttachmentType.Value
newAttachment.Name = attachmentType.."Attachment"
local attachPointOnGun = viewmodel.Handle:FindFirstChild(attachmentType.."Attachment")
attachmentBase.CFrame = (attachPointOnGun.WorldCFrame * attachmentBase.AttachmentPosition.CFrame:Inverse())
local weld = Instance.new("WeldConstraint")
weld.Parent = attachmentBase
weld.Part0 = viewmodel.Handle
weld.Part1 = attachmentBase
end)
Anytime the gun tool is referenced, I get an error. I’m probably doing something horribly wrong, so if you know why this is happening, please tell me, I’m not super good with local scripts, and some information on what I’m doing wrong would be nice. Thanks!
Edit: I think I should add that the attachment is being found, but not the gun, I have no idea why it’s doing this.
Edit 2: Surprisingly wasn’t the fault of the local script, it was the fault of the script creating the gun and calling the module.