This is the main function
local function updateLoadout(class)
if class then -- Ensure class is not nil
local classPrimary = classModule[class.Value].Primary
local classSecondary = classModule[class.Value].Secondary
loadout.Primary = classPrimary.Viewmodel
loadout.Secondary = classSecondary.Viewmodel
if CurrentSlot == 1 then
camera:ClearAllChildren()
task.wait()
currentViewmodel = loadout.Primary:Clone()
currentViewmodel.Parent = camera
local animations = {
["Idle"] = currentViewmodel.AnimationController.Animator:LoadAnimation(currentViewmodel.Animations.Idle),
["Equip"] = currentViewmodel.AnimationController.Animator:LoadAnimation(currentViewmodel.Animations.Equip)
}
animations.Equip:Play()
animations.Idle:Play()
updateViewmodel(currentViewmodel)
elseif CurrentSlot == 2 then
camera:ClearAllChildren()
task.wait()
currentViewmodel = loadout.Secondary:Clone()
currentViewmodel.Parent = camera
local animations = {
["Idle"] = currentViewmodel.AnimationController.Animator:LoadAnimation(currentViewmodel.Animations.Idle),
["Equip"] = currentViewmodel.AnimationController.Animator:LoadAnimation(currentViewmodel.Animations.Equip)
}
animations.Equip:Play()
animations.Idle:Play()
updateViewmodel(currentViewmodel)
end
end
end