kyupita Posted September 25, 2025 Share Posted September 25, 2025 Currently making another character and I wanted to give him a custom backpack that he spawns in with and can't unequip. I'm having an issue with getting him to spawn in with it, but my main problem is that whenever I try to pick it up after spawning it in, my game crashes. I used the code for DST's backpacks and tried using other forum posts for help, but I'm still getting errors..... Idk if this is just a case of me being dumb and misunderstanding things but it seems like no matter what I do I keep getting errors Currently my log says: [string "scripts/containers.lua"]:10: attempt to index local 'container' (a nil value) But none of the fixes I found online worked 😕 modmain and item prefab code: Spoiler Any help is greatly appreciated! Link to comment https://forums.kleientertainment.com/forums/topic/168166-problem-with-custom-backpack/ Share on other sites More sharing options...
FerniFrenito Posted September 25, 2025 Share Posted September 25, 2025 Apparently the problem is being caused by if not TheWorld.ismastersim then inst.OnEntityReplicated = function(inst) inst.replica.container:WidgetSetup("solbag") end end because inst.replica does not contain "container" This may be because you are calling that block of code before placing the "container" component. Maybe it can be solved like this: inst:AddComponent("container") inst.components.container:WidgetSetup("solbag") inst.components.container.skipclosesnd = true inst.components.container.skipopensnd = true if not TheWorld.ismastersim then inst.OnEntityReplicated = function(inst) inst.replica.container:WidgetSetup("solbag") end end If that doesn't work, then you may need to look at the replica components rather than the replica itself. inst:AddComponent("container") inst.components.container:WidgetSetup("solbag") inst.components.container.skipclosesnd = true inst.components.container.skipopensnd = true if not TheWorld.ismastersim then inst.OnEntityReplicated = function(inst) inst.replica.components.container:WidgetSetup("solbag") end end It is difficult to diagnose because I don't know what things are in the replica object when the OnEntityReplicated function is called. Link to comment https://forums.kleientertainment.com/forums/topic/168166-problem-with-custom-backpack/#findComment-1837261 Share on other sites More sharing options...
kyupita Posted September 25, 2025 Author Share Posted September 25, 2025 Thank you for responding! I seem to be having the same error, do you need the entire item file? (I'm new to this sorry 😭) solbag.lua Link to comment https://forums.kleientertainment.com/forums/topic/168166-problem-with-custom-backpack/#findComment-1837289 Share on other sites More sharing options...
FerniFrenito Posted September 25, 2025 Share Posted September 25, 2025 1 hour ago, seraph780 said: Thank you for responding! I seem to be having the same error, do you need the entire item file? (I'm new to this sorry 😭) solbag.lua 3.6 kB · 0 downloads try this: if not TheWorld.ismastersim then inst.OnEntityReplicated = function(inst) inst.replica.components.container:WidgetSetup("solbag") end end Link to comment https://forums.kleientertainment.com/forums/topic/168166-problem-with-custom-backpack/#findComment-1837298 Share on other sites More sharing options...
kyupita Posted September 25, 2025 Author Share Posted September 25, 2025 1 hour ago, FerniFrenito said: try this: if not TheWorld.ismastersim then inst.OnEntityReplicated = function(inst) inst.replica.components.container:WidgetSetup("solbag") end end still getting the same error 😢 do you need any of my other files? Link to comment https://forums.kleientertainment.com/forums/topic/168166-problem-with-custom-backpack/#findComment-1837306 Share on other sites More sharing options...
FerniFrenito Posted September 25, 2025 Share Posted September 25, 2025 1 hour ago, seraph780 said: still getting the same error 😢 do you need any of my other files? If the following doesn't solve the problem, I would like you to send the .zip with your entire mod so I can run the code on my computer. From what I see in the game code, .replica is never used in OnEntityReplicated, which makes me think that inst is the replica itself, but I also saw that that part only handles things like tags and stuff like that. To tell you the truth, I've never understood what object replicas are for, but from what I see, it has something to do with server-client communication. Are you sure you need to do that in the replica? I'm viewing the code for the backpacks in the game, and 1. none of them have the OnEntityReplicated function, and 2. they all use WidgetSetup() only once, after adding the component. I already saw the problem, but I need you to send me the complete traceback. Link to comment https://forums.kleientertainment.com/forums/topic/168166-problem-with-custom-backpack/#findComment-1837313 Share on other sites More sharing options...
kyupita Posted September 26, 2025 Author Share Posted September 26, 2025 2 hours ago, FerniFrenito said: If the following doesn't solve the problem, I would like you to send the .zip with your entire mod so I can run the code on my computer. From what I see in the game code, .replica is never used in OnEntityReplicated, which makes me think that inst is the replica itself, but I also saw that that part only handles things like tags and stuff like that. To tell you the truth, I've never understood what object replicas are for, but from what I see, it has something to do with server-client communication. Are you sure you need to do that in the replica? I'm viewing the code for the backpacks in the game, and 1. none of them have the OnEntityReplicated function, and 2. they all use WidgetSetup() only once, after adding the component. I already saw the problem, but I need you to send me the complete traceback. Honestly I'm not entirely sure what I'm doing with the item's code since this is my first time trying to make something like this.... Also I tried to turn the mod into a zip, but the forums won't let me post them here. Is there some other way to send them? Only way I can think right now is submitting it as an unlisted mod to the steam workshop Link to comment https://forums.kleientertainment.com/forums/topic/168166-problem-with-custom-backpack/#findComment-1837321 Share on other sites More sharing options...
FerniFrenito Posted September 26, 2025 Share Posted September 26, 2025 The error isn't in the code. You can leave it as it was originally. It's in the WidgetSetup("solbag") argument. What is "solbag"? Is it a prefab in your mod? It's weird that it won't let you publish the mod, but yes, you can add me on steam or I can add you and you can publish the mod only for friends. Link to comment https://forums.kleientertainment.com/forums/topic/168166-problem-with-custom-backpack/#findComment-1837322 Share on other sites More sharing options...
kyupita Posted September 26, 2025 Author Share Posted September 26, 2025 1 minute ago, FerniFrenito said: The error isn't in the code. You can leave it as it was originally. It's in the WidgetSetup("solbag") argument. What is "solbag"? Is it a prefab in your mod? It's weird that it won't let you publish the mod, but yes, you can add me on steam or I can add you and you can publish the mod only for friends. Yes, solbag is the name of the item (short for solace's bag) It won't let me post it here since it's too big apparently, my steam is kyupita (friend code: 1040528481) Link to comment https://forums.kleientertainment.com/forums/topic/168166-problem-with-custom-backpack/#findComment-1837323 Share on other sites More sharing options...
FerniFrenito Posted September 26, 2025 Share Posted September 26, 2025 17 hours ago, seraph780 said: Yes, solbag is the name of the item (short for solace's bag) It won't let me post it here since it's too big apparently, my steam is kyupita (friend code: 1040528481) The original problem was that the widget was being set to "backpack" instead of "solbag", so when trying to launch the widget, the game couldn't find the setting for the "solbag" widget because it didn't exist. params.backpack = { widget = { slotpos = {}, animbank = "ui_backpack_2x4", animbuild = "ui_backpack_2x4", --pos = Vector3(-5, -70, 0), pos = Vector3(-5, -80, 0), }, issidewidget = true, type = "pack", openlimit = 1, } for y = 0, 3 do table.insert(params.backpack.widget.slotpos, Vector3(-162, -75 * y + 114, 0)) table.insert(params.backpack.widget.slotpos, Vector3(-162 + 75, -75 * y + 114, 0)) end The solution was simply to change "backpack" to "solbag" params.solbag = { widget = { slotpos = {}, animbank = "ui_backpack_2x4", animbuild = "ui_backpack_2x4", --pos = Vector3(-5, -70, 0), pos = Vector3(-5, -80, 0), }, issidewidget = true, type = "pack", openlimit = 1, } for y = 0, 3 do table.insert(params.solbag.widget.slotpos, Vector3(-162, -75 * y + 114, 0)) table.insert(params.solbag.widget.slotpos, Vector3(-162 + 75, -75 * y + 114, 0)) end modmain.lua solbag.lua 1 Link to comment https://forums.kleientertainment.com/forums/topic/168166-problem-with-custom-backpack/#findComment-1837358 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