I am making this attachment system and I was wondering if I could make a script/function or perhaps a thing inside the script that would check for Attachments
within the table instead of having to manually write what happens if there is a Attachments
inside the Attachments
table
what the table looks like:
Attachments = {
Required = {
Pistolgrip = {
name = "AK-74 bakelite pistol grip",
Type = "Pistolgrip",
AttachedTo = "weapon",
},
Handguard = {
name = "AKS-74U Zenit B-11 handguard",
Type = "Handguard",
AttachedTo = "weapon",
Attachments = {
Slot1 = {
Name = "",
Type = "",
AttachedTo = "AKS-74U Zenit B-11 handguard",
Node = "Tactical1",
},
Slot2 = {
Name = "",
Type = "",
AttachedTo = "AKS-74U Zenit B-11 handguard",
Node = "Foregrip",
},
Slot3 = {
Name = "Kiba Arms 25mm accessory ring mount",
Type = "Mount",
AttachedTo = "AKS-74U Zenit B-11 handguard",
Node = "Tactical2",
Attachments = {
Slot1 = {
Name = "Armytek Predator Pro v3 XHP35 HI flashlight",
Type = "Tactical",
AttachedTo = "Kiba Arms 25mm accessory ring mount",
Node = "Tactical",
},
}
},
Slot4 = {
Name = "",
Type = "Tactical/Optic"
},
},
},
};
};
If I could make the script check each slot automatically for Attachments
, since some attachments are mounts which You will be able to mount Tactical Devices, meaning those mounts will also contain Attachments
table.
the script:
for i,v in pairs(Settings.Attachments.Required) do
if Engine.GunMods:FindFirstChild(i):FindFirstChild(weapon.Name):FindFirstChild(v.name) then
local Attachment = Engine.GunMods:FindFirstChild(i):FindFirstChild(weapon.Name):FindFirstChild(v.name):Clone()
local weldTo= Attachment:FindFirstChild("weldTo")
Attachment.Parent = weapon
if v.AttachedTo == "weapon" then
Attachment:SetPrimaryPartCFrame(weapon.Nodes[weldTo.Value].CFrame)
else
Attachment:SetPrimaryPartCFrame(weapon[Slots.AttachedTo].Nodes[Slots.Node].CFrame)
end
if v.Attachments then
for _,Slots in pairs(v.Attachments) do
if Slots.Name ~= "" then
local SlotAttachment = Engine.GunMods[Slots.Type][weapon.Name][Slots.Name]:Clone()
SlotAttachment.Parent = weapon
SlotAttachment:SetPrimaryPartCFrame(weapon[Slots.AttachedTo].Nodes[Slots.Node].CFrame)
end
end
if v.Attachments.Attachments then
--- same thing repeats
end
end
end
end
Currently I have to make it manually check for Attachments
within Attachments
if You need more details or have questions feel free to ask Me.