I was trying to optimize a script for cloning tools by using a pseudo-try of hashmap, but it isn’t working it’s not cloning the tools, but if I make it by making individual fors it does work, I don’t know if there’s an error in my logic, there’s nothing in console.
Do I have to use any remote events?
-- Other variables
local SS = game.ServerStorage
local Tools = SS.Tools
local Equipment = SS.Equipment
local ARMAS = Tools.Guns
local OtherTools = Tools.OtherTools
local MandoSupremo = Tools["ALTO MANDO"]
local transport = Tools.Transport
-- Equipment folders
local EM = Equipment.EJMEX
local infanteria = EM.Infanteria
local medicos = EM.Medicos
local GAFE = EM.GAFE
local GN = Equipment.GN
local transito = GN.Transito
local MAR = Equipment.MARINA
local fan = MAR.FAN
local unopes = MAR.UNOPES
local PN = MAR.PN
local HCM = Equipment.HCM
local FAM = Equipment.FAM
local bfp = FAM.BFP
local FGR = Equipment.FGR
local AIC = FGR.AIC
local PM = Equipment.PM
local EMP = PM.EMP
local mainMarina = MAR.main
local mainFAM = FAM.main
local hcmMain = HCM.Main
local mainPM = PM.main
local gnMain = GN.main
local emGroupIDs = {
410512, -- 1 EM 8
903262, -- 2 Infantería 5
3101144, -- 3 GEO
32008113, -- 4 GRI
10784679 -- 5 NITRO 9
}
local marinaGroupIDs = {
839872, -- 1 Marina 1
768857, -- 2 FAN 0
767953, -- 3 PN 3
17375163, -- 4 UNOPES 3
984617 -- 5 Guardia Costera 0
}
local famGroupIDs = {
353464, -- 1 FAM 4
8398737 -- 2 BFP 7
}
local gnGroupIDs = {
484846, -- 1 GN 2
1439973, -- 2 Movilidad y Transporte 7
3200811, -- 3 GRI 3
1634738 -- 4 asuntos internos 9
}
local pmGroupIDs = {
3200811, -- 1 PM 2
797628 -- 2 EMP 6
}
local hcmGroupIds = {
479342, -- 1 HCM 2
733550 -- 2 Arma Blindada 7
}
local fgrGroupIds = {
6426691, -- 1 AIC
6426691 -- 1 AIC
}
-- Helper function to clone items to player's backpack
local function cloneItemsToBackpack(player, itemsFolder)
for _, item in pairs(itemsFolder:GetChildren()) do
local clonedItem = item:Clone()
clonedItem.Parent = player.Backpack
end
end
local hashMap = {
[emGroupIDs[5]] = {ARMAS.NITRO, transport.Bicla},
[emGroupIDs[3]] = medicos,
[gnGroupIDs[1]] = gnMain,
[gnGroupIDs[3]] = {ARMAS.Licencia, ARMAS.P90},
[gnGroupIDs[4]] = ARMAS.G19,
[gnGroupIDs[2]] = transito,
[marinaGroupIDs[1]] = mainMarina,
[marinaGroupIDs[4]] = mainMarina,
[marinaGroupIDs[3]] = {ARMAS.ZipTie, mainMarina},
[famGroupIDs[1]] = mainFAM,
[famGroupIDs[2]] = bfp,
[hcmGroupIds[1]] = hcmMain,
[pmGroupIDs[1]] = {ARMAS.G3, mainPM}
}
-- Function to assign equipment based on group IDs
local function onPlayerSpawned(player)
for groupID, equipmentFolder in pairs(hashMap) do
if player:IsInGroup(groupID) then
if type(equipmentFolder) == "table" then
for _, folder in pairs(equipmentFolder) do
cloneItemsToBackpack(player, folder)
end
else
cloneItemsToBackpack(player, equipmentFolder)
end
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
onPlayerSpawned(player)
end)
end)