CreatePed and AttachEntityToEntity Not working

Hello, for some reason when I am trying to create a ped and attach it to the players hand it doesn’t work.
No Ped is created and no errors in the console.

RegisterNetEvent("fishing:anim", function()    
    local playerPed = PlayerPedId()
    local pPos = GetEntityCoords(playerPed)
    local fishHash = "a_c_fish"
    

    theFishObj = CreatePed(28,fishHash, pPos.x, pPos.y, pPos.z, 0, false, true)
    SetEntityCollision(theFishObj , false)
    SetEntityVisible(theFishObj, true, 0)
	AttachEntityToEntity(theFishObj, playerPed, GetPedBoneIndex(playerPed, 57005), 0.15, 0.05, 0.0, -65.0, 0.0, 0.0, 1, 1, 0, 0, 2, 1)



    TaskTurnPedToFaceEntity(ped, playerPed, 1.0)
    TaskTurnPedToFaceEntity(playerPed, ped, 1.0)
    Wait(1000)
    PlayAmbientSpeech1(ped, "Generic_Hi", "Speech_Params_Force")
    Wait(1000)
    FreezeEntityPosition(playerPed, true)  
    RequestAnimDict("mp_safehouselost@")
    while not HasAnimDictLoaded("mp_safehouselost@") do Wait(0) end 
    TaskPlayAnim(playerPed, "mp_safehouselost@", "package_dropoff", 8.0, 1.0, -1, 16, 0, 0, 0, 0)
    Wait(4000)
    DeletePed(theFishObj)
    SetModelAsNoLongerNeeded(theFishObj)
    PlayAmbientSpeech1(ped, "Chat_State", "Speech_Params_Force")
    Wait(500)
    RequestAnimDict("mp_safehouselost@")
    while not HasAnimDictLoaded("mp_safehouselost@") do Wait(0) end
    TaskPlayAnim(ped, "mp_safehouselost@", "package_dropoff", 8.0, 1.0, -1, 16, 0, 0, 0, 0 )
    Wait(3000)
    
    FreezeEntityPosition(playerPed, false)
    
end)

Make sure you request the required model for the ped before creating it:

RequestModel(fishHash)
while not HasModelLoaded(fishHash) do
    Wait(1)
end
1 Like

Thank you Mobius to the rescue, knew i’d be missing something. Problem now is the entity decides to unattach itself from the player hand when TaskPlayAnim and the item drops on the floor during the animation. Im unsure whether this is a script limitation or not. I tried reattaching the fish straight after the anim but that doesn’t work

RegisterNetEvent("fishing:anim", function()    
    local playerPed = PlayerPedId()
    local pPos = GetEntityCoords(playerPed)
    local fishHash = "a_c_fish"
    RequestModel(fishHash)
    while not HasModelLoaded(fishHash) do
        Wait(1)
    end

    theFishObj = CreatePed(28,fishHash, pPos.x, pPos.y, pPos.z, 0, false, true)
    SetEntityCollision(theFishObj , false)
    SetEntityVisible(theFishObj, true, 0)
	AttachEntityToEntity(theFishObj, playerPed, GetPedBoneIndex(playerPed, 57005), 0.15, 0.05, 0.0, -65.0, 0.0, 0.0, 1, 1, 0, 0, 2, 1)
    


    TaskTurnPedToFaceEntity(ped, playerPed, 1.0)
    TaskTurnPedToFaceEntity(playerPed, ped, 1.0)
    Wait(1000)
    PlayAmbientSpeech1(ped, "Generic_Hi", "Speech_Params_Force")
    Wait(1000)
    FreezeEntityPosition(playerPed, true)  
    RequestAnimDict("mp_safehouselost@")
    while not HasAnimDictLoaded("mp_safehouselost@") do Wait(0) end
    AttachEntityToEntity(theFishObj, playerPed, GetPedBoneIndex(playerPed, 57005), 0.15, 0.05, 0.0, -65.0, 0.0, 0.0, 1, 1, 0, 0, 2, 1)
    TaskPlayAnim(playerPed, "mp_safehouselost@", "package_dropoff", 8.0, 1.0, -1, 16, 0, 0, 0, 0)
    AttachEntityToEntity(theFishObj, playerPed, GetPedBoneIndex(playerPed, 57005), 0.15, 0.05, 0.0, -65.0, 0.0, 0.0, 1, 1, 0, 0, 2, 1)
    Wait(4000)
    
    PlayAmbientSpeech1(ped, "Chat_State", "Speech_Params_Force")
    Wait(500)
    RequestAnimDict("mp_safehouselost@")
    while not HasAnimDictLoaded("mp_safehouselost@") do Wait(0) end
    
    TaskPlayAnim(ped, "mp_safehouselost@", "package_dropoff", 8.0, 1.0, -1, 16, 0, 0, 0, 0 )
    Wait(3000)

    DeletePed(theFishObj)
    SetModelAsNoLongerNeeded(theFishObj)
    
    FreezeEntityPosition(playerPed, false)
    
end)

Try setting parameter 13 (isPed) to true:

AttachEntityToEntity(theFishObj, playerPed, GetPedBoneIndex(playerPed, 57005), 0.15, 0.05, 0.0, -65.0, 0.0, 0.0, true, true, false, true, 2, true)
1 Like

Thank you!! :grinning: