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

Backpack GUI system won't work?

Asked by 6 years ago

So I am working on a backpack/inventory system for my game but this script appears to not be working. It works on studio, but doesn't in the actual game. Here is the script and if you need more information, let me know! Thank you!

local Items = {}
local frames = {}
local Equiped = nil
local Player = game.Players.LocalPlayer
local character = Player.Character

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)

function Scan(location)
    for i,v in pairs(location:GetChildren()) do
        if v:IsA("Tool") or v:IsA("HopperBin") then
            table.insert(Items,v)
        end
    end
end

Scan(character)
Scan(Player.Backpack)


function Update()
    print(Equiped)
    for i,v in pairs(frames) do
        v:Destroy()
    end
    for i,v in pairs(Items) do
        local sam = script.Sample:Clone()
        sam.Name = v.Name
        sam.Parent = script.Parent.Holder
        sam.ImageLabel.Image = v.TextureId
        sam.Text = v.Name
        table.insert(frames,sam)
        if Equiped ~= nil and Equiped == v then
            sam.BorderSizePixel = 2
        end
        sam.MouseButton1Click:connect(function()
            if Equiped == nil or Equiped ~= v then
                Equiped = v
                character.Humanoid:UnequipTools()
                character.Humanoid:EquipTool(v)
            else
                Equiped = nil
                character.Humanoid:UnequipTools()
            end
        end)
    end
end

function backpackchanged()
    Items = {}
    Scan(character)
    Scan(Player.Backpack)
    Update()
end

backpackchanged()

Player.Backpack.ChildAdded:connect(backpackchanged)
Player.Backpack.ChildRemoved:connect(backpackchanged)

character.ChildAdded:connect(backpackchanged)
character.ChildRemoved:connect(backpackchanged)
0
Where is this script located in your game? iFizzics 3 — 6y
0
The script is a localscript inside a ScreenGUI and inside this script is a Textbutton. There is a Frame inside the ScreenGui as well casperfox 0 — 6y
0
Is the screen GUI in the StarterGUI or elsewhere? iFizzics 3 — 6y
0
Yes, the ScreenGui is in the StarterGui casperfox 0 — 6y
View all comments (8 more)
0
I'm not very experienced with this but in Line 7, change that to script.Parent.Parent:SetCoreGuiEnabled......... etc. Or set a variable as script.Parent.Parent and use variable:SetCore......... etc. Also did you get any errors in the console when running this? iFizzics 3 — 6y
0
If that worked, I'll explain what happened. iFizzics 3 — 6y
0
Ok i did that and in studio. no error. But in game, I get this error Sample is not a valid member of LocalScript. Sample is inside the localscript btw casperfox 0 — 6y
0
Sorry. Like I said, I'm not as experienced. Hopefully someone else can help you. iFizzics 3 — 6y
0
Ok thank you so much for trying. casperfox 0 — 6y
0
Tell me the errpr message and i can figure it out AnAnonymousDeveloper 77 — 6y
0
Sample is not a valid member of local script. Sample is inside the local script casperfox 0 — 6y
0
Line 11 change to if v:IsA("BackpackItem") then User#19524 175 — 6y

Answer this question