Dantekris2013 1 Report post Posted March 2 (edited) Hello. I want to make a character who will refuse to eat spoiled food, monster meat and raw meat. When character eating a raw or fried mandrake, this error flies out. I can’t understand what’s wrong. I would be very grateful for any help! valentino.lua Edited March 2 by Dantekris2013 Share this post Link to post Share on other sites
Bigfootmech 21 Report post Posted March 2 (edited) attempt to index field 'perishable' (a nil value) you tried to access something on a variable called "perishable". But it failed. Because "perishable" is not a table, in fact, it's even a nil (doesn't exist)! [string "../mods/Valentino/scripts/prefabs/valentino..."]:102 it happened in the file you uploaded, in line 102 looking at your code, line 102 is: and ((inst.components.perishable:IsStale() or inst.components.perishable:IsSpoiled()) Ok, so then, what is this inst, that it couldn't find a perishable component on it? inst.components.eater.PrefersToEat = function(self, inst) --V2C: fruitcake hack. see how long this code stays untouched - _-" return not (inst.prefab == "winter_food4" and self.inst:HasTag("player")) and self:TestFood(inst, self.preferseating) and not (self.inst:HasTag("pickyeater") and ((inst.components.perishable:IsStale() or inst.components.perishable:IsSpoiled()) or inst.prefab == "monstermeat" or inst.prefab == "cookedmonstermeat" or inst.prefab == "monsterlasagna" or inst.prefab == "monstermeat_dried" or (inst:HasTag("edible_MEAT") and inst:HasTag("cookable")))) end So, this is a little confusing (I've not touched that part of the codebase yet), but I'm assuming "inst" in line 102 is supposed to be the food being eaten in the case you stated, "raw, or cooked mandrake" But as far as I know, neither of those spoil. Nor does rot. So I wouldn't expect them to have a "perishable" component. So if you set line 102 to be this instead: and ((inst.components.perishable ~= nil and (inst.components.perishable:IsStale() or inst.components.perishable:IsSpoiled())) I think it should work Basically: check that the food HAS a perishable component. If it doesn't, then it can't be stale, or spoiled, so it's ok It might also help you long-term if you split the whole reaturn logic statement in to more readable parts. But that's up to you Edited March 2 by Bigfootmech Share this post Link to post Share on other sites
Dantekris2013 1 Report post Posted March 2 Oh it really worked! Thank you so much Bigfootmech you are incredible!! 1 Share this post Link to post Share on other sites