With the help of an awesome user on here, I was able to make progress on converting my custom inventory process over to a ModuleScript process. However, I am having a few issues with it. Here is my framework:
I have a weapon (Ancient Sword) in Workspace, with a clickdetector and a string value called "ObjectValue" within, with the sword object value within (AncientSword)
When an item laying on the ground is clicked, an invisible GUI is made visible, with yes/no options to pick it up. It also adds two string values into this GUI. Name and Object Type.
01 | for _,v in next ,game.Workspace.Items:GetChildren() do |
02 | v.ClickDetector.MouseClick:connect( function () |
03 | script.Parent.Parent.Players.LocalPlayer.PlayerGui.Main.PickupItemGui.ImageLabel.Visible = true |
04 | local s = Instance.new( "StringValue" ) |
05 | s.Name = "ResourceType" |
06 | s.Value = v.ObjectType.Value |
07 | s.Parent = game.Players.LocalPlayer.PlayerGui.Main.PickupItemGui.ImageLabel |
There is a script within this GUI that is made visible that has a mousebutton1click connect for both a YES and a NO button. When either one of the buttons are depressed, the GUI is hidden again, and if YES, the button changes briefly to an ON image, and then back off. Then the script looks through my entire inventory window for any Slot with a value of "" (Which is empty), and then changes the LabelButton Text to the ObjectType's NAME and makes that slot Visible. It does this by calling in data from my ModuleScript.
01 | local equip = script.Parent.Parent.Parent.MenuButton.CharacterButton.EquipBox |
02 | local item = script.Parent.Parent.Parent.MenuButton.CharacterButton.ItemBox |
03 | local equipparts = equip:GetChildren() |
04 | local itemparts = item:GetChildren() |
05 | local plr = game.Players.LocalPlayer |
07 | local ResourceManager = require(game.ReplicatedStorage.ResourceManager) |
08 | local resourceType = script:WaitForChild( "ResourceType" , 60 ).Value |
09 | local data = ResourceManager.Resources [ resourceType ] |
13 | print ( 'PickupItemScript Loaded' ) |
19 | script.Parent.Visible = false |
20 | for i, v in pairs (equipparts) do |
22 | if v.SlotValue.Value = = "" then |
24 | v.SlotLabel.Text = data.Name |
25 | v.SlotLabel.Visible = true |
36 | script.Parent.Parent:Destroy() |
39 | script.Parent.yesbutton.MouseButton 1 Click:connect(yes) |
40 | script.Parent.nobutton.MouseButton 1 Click:connect(no) |
Here is my ModuleScript that houses my Item information.
01 | print ( "ResourceManager Loaded" ) |
04 | local ResourceManager = { } |
08 | Name = "Wooden Sword" , |
12 | Name = "Ancient Sword" , |
18 | ResourceManager.Resources = resources |
The first script to click on my items and open the GUI works to open the GUI, but doesn't successfully change the ObjectType data with what is in my ResourceManager ModuleScript.
The second script doesn't work at all as I cannot click on either the YES or NO button.
I believe I know the issue, or at least one of them, but I am unsure of how to fix it. In a few places, my script looks for "ResourceType" in the ResourceManager, but I believe that was a line I was supposed to substitute for an individual resource, ie: "WoodenSword" instead of 'ResourceType". If I am correct in that, then I would need to come up with a solution to automate that process. And have my scripts determine what Item was clicked, and add that item into my custom inventory, without ever having to write "WoodenSword" in that script.
Anyone have any input or advice on where I went wrong?
Thank you!