RadiantRoma Posted March 31, 2017 Share Posted March 31, 2017 (edited) 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.inventory:DropItem(inst) player.components.talker:Say("She woudn't want me to touch this.") end) end end 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! client_log.txt Edited March 31, 2017 by Cherryzion Link to comment Share on other sites More sharing options...
Serpens Posted March 31, 2017 Share Posted March 31, 2017 (edited) 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 March 31, 2017 by Serpens Link to comment Share on other sites More sharing options...
RadiantRoma Posted March 31, 2017 Author Share Posted March 31, 2017 1 hour ago, Serpens said: if player and player:HasTag("player") and player.components and player.components.inventory then Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now