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)

9 comments

0

Hmmmmmmm. I wonder why you wouldn't know where to put a code you made. HMMMMMM  

0

Yes...I wonder

0

It is because it didn't work in the place he thought it would.

0

..

0

Ph is right. that's what i'm asking, where should i put it>

0

Its a joke my guy

0

"meme review"

0

what does the script do?

0

custom inventory system.