BombardmentPigs Posted October 27, 2023 Share Posted October 27, 2023 (edited) Hello, I want to create this custom resource that, when it perishes/spoils it explodes, dealing damage to the player and things around them. I want this to be able to happen inside the inventory or outside the inventory. However, my current code crashes the server whenever the resource is crafted or spawned in. This is the code that is supposed to trigger an explosion when the resource spoils: local prefabs = { "explode_small", } local function OnPerishFn(inst) inst.SoundEmitter:KillSound("hiss") SpawnPrefab("explode_small").Transform:SetPosition(inst.Transform:GetWorldPosition()) inst.components.explosive:OnBurnt() end And this is the explosive and perishable components section of the prefab: inst:AddComponent("explosive") inst.components.explosive.explosivedamage = 15 inst:AddComponent("perishable") inst.components.perishable:SetPerishTime(180) inst.components.perishable:StartPerishing() inst.components.perishable:SetOnPerishFn(fn) Any assistance would be appreciated! Edited October 27, 2023 by BombardmentPigs Link to comment Share on other sites More sharing options...
Haruhi Kawaii Posted October 27, 2023 Share Posted October 27, 2023 1 hour ago, BombardmentPigs said: Hello, I want to create this custom resource that, when it perishes/spoils it explodes, dealing damage to the player and things around them. I want this to be able to happen inside the inventory or outside the inventory. However, my current code crashes the server whenever the resource is crafted or spawned in. This is the code that is supposed to trigger an explosion when the resource spoils: local prefabs = { "explode_small", } local function OnPerishFn(inst) inst.SoundEmitter:KillSound("hiss") SpawnPrefab("explode_small").Transform:SetPosition(inst.Transform:GetWorldPosition()) inst.components.explosive:OnBurnt() end And this is the explosive and perishable components section of the prefab: inst:AddComponent("explosive") inst.components.explosive.explosivedamage = 15 inst:AddComponent("perishable") inst.components.perishable:SetPerishTime(180) inst.components.perishable:StartPerishing() inst.components.perishable:SetOnPerishFn(fn) Any assistance would be appreciated! Try this: inst.components.perishable:SetOnPerishFn(OnPerishFn) Link to comment Share on other sites More sharing options...
BombardmentPigs Posted October 27, 2023 Author Share Posted October 27, 2023 9 hours ago, Haruhi Kawaii said: Try this: inst.components.perishable:SetOnPerishFn(OnPerishFn) Sorry, still crashes. Link to comment Share on other sites More sharing options...
BombardmentPigs Posted October 27, 2023 Author Share Posted October 27, 2023 9 hours ago, Haruhi Kawaii said: Try this: inst.components.perishable:SetOnPerishFn(OnPerishFn) Ok I realised the problem was somewhere else, so this would've helped. Thanks! The problem was that i was trying to set the item max stack size to 30 which was not allowed so now it is changed to 20 and all the code works perfectly. 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