Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Could someone help debug my custom inventory scripts? [ModuleScript]

Asked by
Morficc 36
7 years ago
Edited 7 years ago

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.

for _,v in next,game.Workspace.Items:GetChildren()do
v.ClickDetector.MouseClick:connect(function()
        script.Parent.Parent.Players.LocalPlayer.PlayerGui.Main.PickupItemGui.ImageLabel.Visible = true
        local s = Instance.new("StringValue")
        s.Name = "ResourceType"
        s.Value = v.ObjectType.Value
        s.Parent = game.Players.LocalPlayer.PlayerGui.Main.PickupItemGui.ImageLabel

        end)
end

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.

local equip = script.Parent.Parent.Parent.MenuButton.CharacterButton.EquipBox
local item = script.Parent.Parent.Parent.MenuButton.CharacterButton.ItemBox
local equipparts = equip:GetChildren()
local itemparts = item:GetChildren()
local plr = game.Players.LocalPlayer

local ResourceManager = require(game.ReplicatedStorage.ResourceManager)
local resourceType = script:WaitForChild("ResourceType", 60).Value
local data = ResourceManager.Resources[resourceType]
--Use the data accordingly. ex, to get the image, use "data.Image".


print('PickupItemScript Loaded')
function yes()
script.Parent.yesbutton.Image = "http://www.roblox.com/asset/?id=674373802"
wait(.3)
script.Parent.yesbutton.Image = "http://www.roblox.com/asset/?id=674373565"
wait(.2)
script.Parent.Visible = false
for i, v in pairs(equipparts) do
    wait(0.5)
    if v.SlotValue.Value == "" then
        v.Amount.Value = "1"
        v.SlotLabel.Text = data.Name
        v.SlotLabel.Visible = true
        break
    end
    end
end

function no()
script.Parent.nobutton.Image = "http://www.roblox.com/asset/?id=674374266"
wait(.4)
script.Parent.nobutton.Image = "http://www.roblox.com/asset/?id=674374562"
wait(.3)
script.Parent.Parent:Destroy()
end

script.Parent.yesbutton.MouseButton1Click:connect(yes)
script.Parent.nobutton.MouseButton1Click:connect(no)

Here is my ModuleScript that houses my Item information.

print("ResourceManager Loaded")

--Resource Types
local ResourceManager = {}
local resources = {

    WoodSword = {
                Name = "Wooden Sword",    
                Type = "Slashing"
    },
    AncientSword = {
        Name = "Ancient Sword",
                Type = "Slashing"
    }
}


ResourceManager.Resources = resources --allow other scripts to access this table
return ResourceManager

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!

1 answer

Log in to vote
0
Answered by
Morficc 36
7 years ago

I was able to figure this out mostly and get it to work. I just wasn't seeing the full picture. The "ResourceType" was actually referring to the value being created within my GUI object. So when my other screen was

script:WaitForChild("ResourceType").Value

, it was waiting for that value to be added into the GUI. And to make it kick off, I had to change it to

script.Parent:WaitForChild("ResourceType").Value

as it was not directing to the right location.

As for my yesbutton and nobuttons not connecting, I am still not sure why they were not functioning, but previously I had collected all of my GUI elements underneath one ScreenGui named "Main". For testing, I moved this particular GUI element out of Main and into its own separate ScreenGui, and the buttons began working fine.

Ad

Answer this question