Quick viewmodel hands question

Just having a slight error, not sure why…



function PLAYER:UpdateHands()
    local oldHands = self:GetHands()
    if(IsValid(oldHands)) then oldHands:Remove() end
    
    local hands = ents.Create("gmod_hands")
    if(IsValid(hands)) then
        self:SetHands(hands)
        hands:SetOwner(self)

        local info = player_manager.RunClass(self,"GetHandsModel")
        if(info) then
            hands:SetModel(info.model)
            hands:SetSkin(info.skin)
            hands:SetBodyGroups(info.body)
        end
        local vm = self:GetViewModel(0)
        hands:AttachToViewmodel(vm)
        vm:DeleteOnRemove(hands)      --This errors saying im trying to use a null entity
        self:DeleteOnRemove(hands)
        hands:Spawn()
    end
end


Im then running:



--serverside PlayerInitialSpawn function here
ply:UpdateHands()


If the vm:DeleteOnRemove line is removed, everything seems to work fine. What gives?

Is vm valid?

No, printing the results of isvalid is false. Turns out its valid if I call it from the PlayerSpawn instead of the InitialPlayerSpawn. Thanks for your reply.