Jump to content

Drop-On-Pickup Character Exclusive Error

Recommended Posts

I have a custom item that I want only my character  to be able to pick up. I based my code off of this post here for it, here is the code. It's in the local function fn().

    inst.components.inventoryitem.onputininventoryfn = function(inst, player, inventory)       
        if player.prefab ~= "wisniowski" then            
            inst:DoTaskInTime(0.1, function()               
                player.components.talker:Say("She woudn't want me to touch this.")         

When I try to put it into a container (like a backpack), I get this error (in the crash log, which I will upload too)

[00:00:55]: [string "../mods/Wisniowski/scripts/prefabs/sleepbag..."]:106: attempt to index field 'inventory' (a nil value)
LUA ERROR stack traceback:
    ../mods/Wisniowski/scripts/prefabs/sleepbag.lua:106 in (field) fn (Lua) <105-108>
    scripts/scheduler.lua:177 in (method) OnTick (Lua) <155-207>
    scripts/scheduler.lua:371 in (global) RunScheduler (Lua) <369-377>
    scripts/update.lua:170 in () ? (Lua) <149-228>

Any help resolving this issue would be greatly appreciated!


Edited by Cherryzion
Link to comment
Share on other sites

Most of the time the logfile (errormessage) is helpful, so read it ;)
the log message says, that inventory is nil.
And you have some code about inventory.
So easiest solution would be a check, if inventory exist, before you try to call the "DropItem" function (same for the say function from talker, backpack has not talker ;) )
Put a if line in front of it:
if player and player:HasTag("player") and player.components and player.components.inventory then

Edited by Serpens
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...