this is a temporary solution I found to fix the problem. I hope it helps
RegisterNuiCallback('changeClothesState', function(data, cb)
if AnimPlaying then return end
if LastIndexes[data.clothing] then
local animation = Config.Clothing[data.clothing].animation
while not HasAnimDictLoaded(animation.dict) do RequestAnimDict(animation.dict) Wait(100) end
if IsPedInAnyVehicle(PlayerPedId()) then animation.move = 51 end
TaskPlayAnim(PlayerPedId(), animation.dict, animation.name, 3.0, 3.0, animation.duration, animation.move, 0, false, false, false)
AnimPlaying = true
local pause = animation.duration - 500 if pause < 500 then pause = 500 end
Wait(pause)
AnimPlaying = false
if ClothingTable[data.clothing].type == 'component' then
if ClothingTable[data.clothing].id == 11 then
SetPedComponentVariation(PlayerPedId(), 3, varTorso, texTorso)
end
SetPedComponentVariation(PlayerPedId(), ClothingTable[data.clothing].id, LastIndexes[data.clothing], LastTextureIndexes[data.clothing])
else
SetPedPropIndex(PlayerPedId(), ClothingTable[data.clothing].id, LastIndexes[data.clothing], LastTextureIndexes[data.clothing])
end
LastIndexes[data.clothing] = nil
LastTextureIndexes[data.clothing] = nil
SendNUIMessage({ type = 'UpdateStates', clothingStates = GetClothingState() })
else
local clothingStates = GetClothingState()
if not clothingStates[data.clothing] then return ESX.ShowNotification('Nulla da cambiare', 'error') end
local animation = Config.Clothing[data.clothing].animation
while not HasAnimDictLoaded(animation.dict) do RequestAnimDict(animation.dict) Wait(100) end
if IsPedInAnyVehicle(PlayerPedId()) then animation.move = 51 end
AnimPlaying = true
TaskPlayAnim(PlayerPedId(), animation.dict, animation.name, 3.0, 3.0, animation.duration, animation.move, 0, false, false, false)
local pause = animation.duration - 500 if pause < 500 then pause = 500 end
Wait(pause)
AnimPlaying = false
if ClothingTable[data.clothing].type == 'component' then
LastIndexes[data.clothing] = GetPedDrawableVariation(PlayerPedId(), ClothingTable[data.clothing].id)
LastTextureIndexes[data.clothing] = GetPedTextureVariation(PlayerPedId(), ClothingTable[data.clothing].id)
varTorso = GetPedDrawableVariation(PlayerPedId(), 3)
texTorso = GetPedTextureVariation(PlayerPedId(), 3)
local gender = GetEntityModel(PlayerPedId())
if gender == GetHashKey("mp_m_freemode_01") then
if ClothingTable[data.clothing].id == 11 then
SetPedComponentVariation(PlayerPedId(), 3, 15, 0, 0)
end
SetPedComponentVariation(PlayerPedId(), ClothingTable[data.clothing].id, Config.Clothing[data.clothing].default.male, 0)
elseif gender == GetHashKey("mp_f_freemode_01") then
if ClothingTable[data.clothing].id == 11 then
SetPedComponentVariation(PlayerPedId(), 3, 15, 0, 0)
end
SetPedComponentVariation(PlayerPedId(), ClothingTable[data.clothing].id, Config.Clothing[data.clothing].default.female, 0)
end
else
LastIndexes[data.clothing] = GetPedPropIndex(PlayerPedId(), ClothingTable[data.clothing].id)
LastTextureIndexes[data.clothing] = GetPedPropTextureIndex(PlayerPedId(), ClothingTable[data.clothing].id)
ClearPedProp(PlayerPedId(), ClothingTable[data.clothing].id)
end
SendNUIMessage({ type = 'UpdateStates', clothingStates = GetClothingState() })
end
end)