(type IPhysicsObject) (Object was NULL or not of the right type)

So everytime I plane a banana, this code gets executed to make the banana tree. I see the banana tree and the bunch of bananas attatched to the tree but I can walk through them and the physgun/gravgun can’t grab them.



function GM.MakeBanana(pos,num,owner)
    local plant = ents.Create("prop_physics")
    plant:SetAngles(Angle(0,math.random(1,360),0))
    plant:SetModel("models/props/de_dust/du_palm_tree01_skybx.mdl")
    plant:SetPos(pos + Vector(0, 0, -3))
    plant:Spawn()
    plant:Fadein()
    plant:RiseFromGround(1,50)
    plant.Children = 0
    plant.StrandedProtected = true
    SPropProtection.PlayerMakePropOwner(owner, plant)

    for i = 1,num do
        local ent = ents.Create("prop_physics")
        ent:SetAngles(Angle(0,math.random(1,360),0))
        ent:SetModel("models/props/cs_italy/bananna_bunch.mdl")
        ent:SetPos(pos + Vector(math.random(-7,7),math.random(-7,7),math.random(48,55)))
        ent:Spawn()

        local phys = ent:GetPhysicsObject()
        if phys then 
            phys:EnableMotion(false)  -- The problem seems to be here.
        end
        ent.StrandedProtected = true
        ent:Fadein()
        ent.PlantParent = plant
        plant.Children = plant.Children + 1

        ent:SetHealth(99999)
        SPropProtection.PlayerMakePropOwner(owner, ent)
    end
end


Here’s the error:
ERROR!: Can’t create physics object for models/props/de_dust/du_palm_tree01_skyb
x.mdl
ERROR!: Can’t create physics object for models/props/cs_italy/bananna_bunch.mdl
Timer Error: …modes\gmstranded\entities\entities\gms_seed\init.lua:155: Tried
to use invalid object (type IPhysicsObject) (Object was NULL or not of the right
type)

I could care less for the tree since it will disappear if the banana gets eaten, however the bananas can’t even be used/eaten so how do I fix the bunch of bananas?

  1. Make sure you use Entity.Activate when creating entities. So just add

ent:Activate()

after ent:Spawn().

  1. Instead of just checking to see if the physobj is there, make sure it’s valid, so say

if IsValid(phys) then

Thanks for the reply, I managed to get rid of the Timer Error: …modes\gmstranded\entities\entities\gms_seed\ini t.lua:155: Tried
to use invalid object (type IPhysicsObject) (Object was NULL or not of the right
type)

However, I get ERROR!: Can’t create physics object for models/props/cs_italy/bananna_bunch.mdl
So I still can’t physgun/gravgun or eat the banana bunch.

Also, another strange thing is what I get on console when I type this:
] gm_spawn models/props/cs_italy/bananna_bunch.mdl
ℳℴℯ❤eNergizer<STEAM_0:1:14478438> spawned effect models/props/cs_italy/bananna_bunch.mdl

I don’t see the banana bunch, probably because it’s gmod stranded. But still, is it normal for it to be an effect?

] gm_spawn models/props_junk/watermelon01.mdl
ℳℴℯ❤eNergizer<STEAM_0:1:14478438> spawned model models/props_junk/watermelon01.mdl

That’s what I get when I spawn the watermelon which is edible and can be physgunned/gravgunned.

I’m guessing the reason the bananas are not working is because the bananas are seen as an effect, I don’t know how or where it was coded to be an effect.

Any ideas?

I FINALLY FIXED IT! The problem was that I didn’t have Counter Strike: Source installed on my dedicated server too. The reason the entity wasn’t created properly because the server didn’t know what the models/props/cs_italy/bananna_bunch.mdl model was since it’s derived from CS:S which is not installed. So after installing CS:S, I managed to get the fruits working.