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

Where do I put this piece of code i made?

Asked by 6 years ago

for my backpack GUI i made, i made this piece of code, but i don't know where to put it, since i tried it in the place i wanted it to be, but it didn't work. Snippet of Code:

function onKeyPress(inputObject)
    local key = inputObject.KeyCode.Name
    local value = inputKeys[key]
    if value and UserInputService:GetFocusedTextBox() == nil then 
        handleEquip(value["tool"])
    end 
end

and the script i need to put the piece of code in:

local Items = {}
local frames = {}
local Equiped = nil
local Player = game.Players.LocalPlayer
local Character = Player.Character
local UserInputService = game:GetService("UserInputService")

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

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

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
Hmmmmmmm. I wonder why you wouldn't know where to put a code you made. HMMMMMM   Axceed_Xlr 380 — 6y
0
Yes...I wonder ThatPreston 354 — 6y
0
It is because it didn't work in the place he thought it would. User#21908 42 — 6y
0
.. User#20388 0 — 6y
View all comments (5 more)
0
Ph is right. that's what i'm asking, where should i put it> Joshuasol 2 — 6y
0
Its a joke my guy Zafirua 1348 — 6y
0
"meme review" Joshuasol 2 — 6y
0
what does the script do? awesomeipod 607 — 6y
0
custom inventory system. Joshuasol 2 — 6y

Answer this question