Crafting System issue? Issue with code or with ROBLOX Studio?

So, I’m currently working on a crafting system for my game. All the relevant code and explorer items should be shown in the video, if there is anything else you need to know, feel free to ask for it. The issue I’m having is as follows;
When I have the WoodSword begin in the starterGUI.CraftingGui.CraftingOverframe.CraftsDisplay, the server-side code runs just fine, 0 issues. But, when I have it start in the replicatedStorage then moved into the playerGui.CraftingGui.CraftingOverFrame.CraftsDisplay (like what would normally happen during gameplay), suddenly there’s an error for “attempt to index nil with “Craft Button”” despite the only different being where the GUI itself starts on loading into the game? The reason for the title is because occasionally I write code that doesn’t work, for some reason, leave it for a few days unchanged, then it just suddenly works completely as intended? I’m wondering if this is that case or if there is an issue with my code and how I can go about fixing it.

1 Like

Looks like a hierarchy issue to me, like where parents and ui objects are.

1 Like

I’m not finding any obvious hierarchy issues. I did find, however, that itemName, while being passed correctly (in this case WoodSword like in the first part of the video) when it starts in the StarterGui, itenName is coming up as nil instead of WoodSword when it starts in my GuiFolder in ReplicatedStorage. Although, it only comes up as nil through ‘FindFirstChild’. I tried checking if it was nil immediately beforehand with a print statement and it printed WoodSword as expected.

Edit: I’ve managed to confirm the issue doesn’t lie with the hierarchy, as the script itself looks for the gui in playerGui, where the gui ends up regardless of it starts in StarterGui or is called directly the the player’s playerGui. Is there some other reason the script only works when the gui is in StarterGui, even though it ends up in playerGui regardless?

With a brief read on, OnServerEvent, isn’t that server sided? Then you are trying to access the players gui (client sided) from the server which won’t work.

But, if you put said code into the client (the gui), i think it’s acting locally, but when moved from replicated to the gui, there’s confliction.

I would make sure you are coding the right logic (server on the server, client on the client) respectively.

Accessing the specific player’s playerGui from the server is, indeed, doable. The if #inventory == 1 then line of code is doing just that, just with the player’s inventory GUI and looking for that one’s children to see if it’s equal to or more than 1 (unless the player somehow deletes the UIGridLayout object, #inventory should always print as at least 1). One of the first thing’s defined is exactly which player client to look in for both as well. So, I don’t think it’s that I can’t access the player’s gui from the server (again, the same server script can access the player’s inventory gui and it’s children (also client-sided) just fine), which is only adding to my confusion on this topic.

Just because it works doesn’t mean it’s right. You shouldn’t do anything directly to a gui, from the server, you should remoteEvent where possible.

This can be the underlying cause of your issues. I would sort out my server/client logic respectively.