How do i connect button to open inventory system?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to connect the button into the inventory system by pressing key and mouse clicking
    when i press by the key it will open the inventory and if i click it by mouse it will open it as well close or open


    as you can see i have the inventory here but its not working to connect for the open/close button
    by pressing with the key and the mouse clicking

  2. What is the issue? Include screenshots / videos if possible!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    No solution at all sadly

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

In a local script parented to the button:

local inv = "PATH TO YOUR INVENTORY SCREENGUI"

script.Parent.Activated:Connect(function()
	inv.Enabled = not inv.Enabled
end)
1 Like

Sadly that didnt work but

here the script if u wanna check it out

local uis = game:GetService(“UserInputService”)
local starterGui = game:GetService(“StarterGui”)
local tweenService = game:GetService(“TweenService”)

starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

local CurrentSlotEquipped = “”

local player = game.Players.LocalPlayer
local char = workspace:WaitForChild(player.Name) – added WaitForChild
local bp = player.Backpack
local hum = char:WaitForChild(“Humanoid”)

local frame = script.Parent:WaitForChild(“Frame”)
local inventory = script.Parent:WaitForChild(“Inventory”)
local ScrollFrame = inventory.ImageLabel.ScrollingFrame

local equippedTransparency = 0.2
local unequippedTrnasparency = .35

local Dragging = false

local ItemDragged = nil
local PasteItem = nil

local mouse = player:GetMouse()
local MouseGui = script.Parent:WaitForChild(“Template”)

local equippedInfo = TweenInfo.new(
0.25,
Enum.EasingStyle.Quad,
Enum.EasingDirection.In,
0,
false,
0
)

local OwnedTools = {}

table.insert(OwnedTools,1,“”)
for i = 1, 9 do
table.insert(OwnedTools, #OwnedTools + 1 ,“”)
end

local function SelectToolGui(except,reset,NewTool)
for i,v in pairs(frame:GetChildren())do
if v:IsA(“TextButton”) then
local goal = {BackgroundColor3 = Color3.fromRGB(31, 31, 31), BackgroundTransparency = unequippedTrnasparency}
local tween = tweenService:Create(v, equippedInfo, goal)
tween:Play()
end
end

for i,v in pairs(ScrollFrame:GetChildren())do
	if v:IsA("TextButton")then
		local goal = {BackgroundColor3 = Color3.fromRGB(31, 31, 31)}
		local tween = tweenService:Create(v, equippedInfo, goal)
		tween:Play()
	end
end

if reset then
	CurrentSlotEquipped = ""
else
	if CurrentSlotEquipped ~= except then
		if except <= 9 then
			CurrentSlotEquipped = except
			local selectedPart = frame:FindFirstChild(tostring(except))
			local goal = {BackgroundColor3 = Color3.fromRGB(149, 149, 149), BackgroundTransparency = equippedTransparency}
			local tween = tweenService:Create(selectedPart, equippedInfo, goal)
			tween:Play()
		else
			CurrentSlotEquipped = except
			local selectedPart = ScrollFrame:WaitForChild(tostring(except))
			local goal = {BackgroundColor3 = Color3.fromRGB(149, 149, 149)}
			local tween = tweenService:Create(selectedPart, equippedInfo, goal)
			tween:Play()
		end
	elseif CurrentSlotEquipped == except then
		CurrentSlotEquipped = ""
	end
end
if  NewTool ==  nil then
	local ToolForEquipping = OwnedTools[CurrentSlotEquipped]
	script.Toolbar:FireServer(CurrentSlotEquipped,ToolForEquipping)
end

end

local function ToolAdded(child,parent)
if child:IsA(“Tool”) and table.find(OwnedTools,child) == nil then

	if table.find(OwnedTools,"")then
		local emptySpot = table.find(OwnedTools,"")
		table.remove(OwnedTools,emptySpot)
		table.insert(OwnedTools,emptySpot,child)
		if parent == char then
			SelectToolGui(emptySpot,nil,true)
		end
	else
		table.insert(OwnedTools, #OwnedTools + 1 ,child)
		if parent == char then
			SelectToolGui(#OwnedTools,nil,true)
		end
	end
end

end

local function CheckForTools()
for i,v in pairs(bp:GetChildren())do
ToolAdded(v,bp)
end

for i,v in pairs(char:GetChildren())do
	ToolAdded(v,char)
end

end

local function ToolParentChanged()
for i,v in pairs(OwnedTools)do
if v ~= “” then
if v.Parent ~= char and v.Parent ~= bp then
table.remove(OwnedTools,i)
if ScrollFrame:FindFirstChild(tostring(i))then
ScrollFrame:FindFirstChild(tostring(i)):Destroy()
end
table.insert(OwnedTools,i,“”)
end
end
end
end

for i,v in pairs(frame:GetChildren())do
if v:IsA(“TextButton”) then
if v.Item.Value ~= nil then
v.ToolName.Text = tostring(v.Item.Value)
else
v.ToolName.Text = “”
end
end
end
CheckForTools()

for i,v in pairs(frame:GetChildren())do
if v:IsA(“TextButton”) then
v.Item.Changed:Connect(function()
if v.Item.Value ~= nil then
v.ToolName.Text = tostring(v.Item.Value)
else
v.ToolName.Text = “”
end
end)
v.MouseButton1Down:Connect(function()
if v.Item.Value ~= nil then
if inventory.Visible == false then
SelectToolGui(tonumber(v.Name))
end
end
end)
end
end

uis.InputBegan:Connect(function(Input,GP)
if (GP) then return end
if(Input.KeyCode == Enum.KeyCode.One) and frame[“1”].Item.Value ~= nil then
SelectToolGui(1)
elseif(Input.KeyCode == Enum.KeyCode.Two) and frame[“2”].Item.Value ~= nil then
SelectToolGui(2)
elseif(Input.KeyCode == Enum.KeyCode.Three) and frame[“3”].Item.Value ~= nil then
SelectToolGui(3)
elseif(Input.KeyCode == Enum.KeyCode.Four) and frame[“4”].Item.Value ~= nil then
SelectToolGui(4)
elseif(Input.KeyCode == Enum.KeyCode.Five) and frame[“5”].Item.Value ~= nil then
SelectToolGui(5)
elseif(Input.KeyCode == Enum.KeyCode.Six) and frame[“6”].Item.Value ~= nil then
SelectToolGui(6)
elseif(Input.KeyCode == Enum.KeyCode.Seven) and frame[“7”].Item.Value ~= nil then
SelectToolGui(7)
elseif(Input.KeyCode == Enum.KeyCode.Eight) and frame[“8”].Item.Value ~= nil then
SelectToolGui(8)
elseif(Input.KeyCode == Enum.KeyCode.Nine) and frame[“9”].Item.Value ~= nil then
SelectToolGui(9)
elseif (Input.KeyCode == Enum.KeyCode.Backquote) then

	inventory.Search.TextBox.Text = ""
	inventory.Visible = not inventory.Visible
elseif (Input.KeyCode == Enum.KeyCode.Backspace) then
	SelectToolGui(1,"true")
end

end)

char.ChildAdded:Connect(function(child)
ToolAdded(child,char)
end)

bp.ChildAdded:Connect(function(child)
ToolAdded(child,bp)
end)

local function upDateToolBar()
for i,v in pairs(OwnedTools)do
for a,b in pairs(frame:GetChildren())do
if b.Name == tostring(i) then
if v ~= “” then
b.Visible = true
b.Item.Value = v
b.ToolName.Text = v.Name
else
b.Visible = false
b.ToolName.Text = “”
b.Item.Value = nil
end

			if inventory.Visible == true then
				b.Visible = true
			end
		end
	end
end

end

local function CreateButtonForTool(i,v)
local template = script.Template
local searchBar = inventory.Search.TextBox

local NewButton =  template:Clone()
NewButton.Parent = inventory.ImageLabel.ScrollingFrame
NewButton.Visible =  true
NewButton.ToolName.Text = tostring(v.Name)
NewButton.Name = tostring(i)

searchBar:GetPropertyChangedSignal("Text"):Connect(function()
	local InputText: string = string.lower(searchBar.Text)
	for _, Button: Instance in inventory.ImageLabel.ScrollingFrame:GetChildren() do
		if Button:IsA("TextButton") then
			Button.Visible = string.find(string.lower(Button.ToolName.Text), InputText, 1, true) and true or false
		end
	end
end)

NewButton.MouseButton2Click:Connect(function()
	if table.find(OwnedTools,"")then
		local NewEmptySpot = table.find(OwnedTools,"")

		if NewEmptySpot < 10 then
			table.remove(OwnedTools,NewEmptySpot)
			table.insert(OwnedTools,NewEmptySpot,v)
			table.remove(OwnedTools,i)
			table.insert(OwnedTools,i,"")
			NewButton:Destroy()
		end
	end
end)

local gui = NewButton	

gui.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and inventory.Visible == true and ItemDragged == nil and Dragging == false  then
		Dragging =  true
		gui.Visible = false

		ItemDragged = tonumber(gui.Name)
		MouseGui.Number.Text = ""
		MouseGui.ToolName.Text = gui.ToolName.Text
		MouseGui.Visible = true
	end
end)		
gui.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and Dragging == true and ItemDragged == tonumber(gui.Name) then
		Dragging =  false
		gui.Visible = true
		local goal = {BackgroundColor3 = Color3.fromRGB(31, 31, 31), BackgroundTransparency = unequippedTrnasparency}
		local tween = tweenService:Create(gui, equippedInfo, goal)
		tween:Play()
		MouseGui.Visible = false

		if PasteItem ~= nil then

			if PasteItem ~= inventory then
				local PasteItemIndex = tonumber(PasteItem.Name)
				table.insert(OwnedTools,PasteItemIndex,OwnedTools[ItemDragged])
				table.remove(OwnedTools,ItemDragged+1)
				table.insert(OwnedTools,ItemDragged+1,OwnedTools[PasteItemIndex+1])
				table.remove(OwnedTools,PasteItemIndex+1)
				gui:Destroy()
			end
		end

		ItemDragged = nil
	end
end)

end

inventory.MouseEnter:Connect(function()
PasteItem = inventory
end)

inventory.MouseLeave:Connect(function()
PasteItem = nil
end)

for i,gui in pairs(frame:GetChildren()) do
if gui:IsA(“TextButton”)then

	gui.MouseEnter:Connect(function()
		PasteItem = gui
	end)
	gui.MouseLeave:Connect(function()
		if PasteItem == gui then
			PasteItem = nil
		end
	end)

	gui.MouseButton2Click:Connect(function()
		if gui.Item.Value ~= nil and inventory.Visible == true then
			local guiPlace = tonumber(gui.Name)

			if OwnedTools[10] == ""then
				table.remove(OwnedTools,10)
				table.insert(OwnedTools,10,OwnedTools[guiPlace])

				if CurrentSlotEquipped == tonumber(gui.Name) then
					SelectToolGui(true,true)
				end


			elseif OwnedTools[10] ~= "" then
				local Once =  false
				for i,v in pairs(OwnedTools)do
					if i > 10 and Once == false then
						if v == "" then
							Once = true
							table.remove(OwnedTools,i)
							table.insert(OwnedTools,i,OwnedTools[guiPlace])	
							if CurrentSlotEquipped == tonumber(gui.Name) then
								SelectToolGui(true,true)
							end

							break
						end

					end
				end

				if Once == false then
					table.insert(OwnedTools, #OwnedTools + 1 , OwnedTools[guiPlace])
				end
			end
			table.remove(OwnedTools,guiPlace)
			table.insert(OwnedTools,guiPlace,"")
		end
	end)

	gui.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 and inventory.Visible == true and ItemDragged == nil and Dragging == false and gui.Item.Value ~= nil then
			Dragging =  true
			gui.Visible = false

			ItemDragged = tonumber(gui.Name)
			MouseGui.Number.Text = gui.Number.Text
			MouseGui.ToolName.Text = gui.ToolName.Text
			MouseGui.Visible = true
		end
	end)		
	gui.InputEnded:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 and Dragging == true and ItemDragged == tonumber(gui.Name) then
			Dragging =  false
			gui.Visible = true
			
			local goal = {BackgroundColor3 = Color3.fromRGB(31, 31, 31), BackgroundTransparency = unequippedTrnasparency}
			local tween = tweenService:Create(gui, equippedInfo, goal)
			tween:Play()
			MouseGui.Visible = false

			if PasteItem ~= nil then
				if PasteItem == inventory then
					if OwnedTools[10] == ""then
						table.remove(OwnedTools,10)
						table.insert(OwnedTools,10,OwnedTools[ItemDragged])

						if CurrentSlotEquipped == tonumber(gui.Name) then
							SelectToolGui(true,true)
						end

					elseif OwnedTools[10] ~= "" then
						local Once =  false
						for i,v in pairs(OwnedTools)do
							if i > 10 and Once == false then
								if v == "" then
									Once = true
									table.remove(OwnedTools,i)
									table.insert(OwnedTools,i,OwnedTools[ItemDragged])
									if CurrentSlotEquipped == tonumber(gui.Name) then
										SelectToolGui(true,true)
									end
									break
								end

							end
						end

						if Once == false then
							table.insert(OwnedTools, #OwnedTools + 1 ,OwnedTools[ItemDragged])
						end
					end
					table.remove(OwnedTools,ItemDragged)
					table.insert(OwnedTools,ItemDragged,"")
				else
					local PasteItemIndex = tonumber(PasteItem.Name)

					if ItemDragged < PasteItemIndex then
						table.insert(OwnedTools,PasteItemIndex,OwnedTools[ItemDragged])
						table.remove(OwnedTools,ItemDragged)
						table.insert(OwnedTools,ItemDragged,OwnedTools[PasteItemIndex])
						table.remove(OwnedTools,PasteItemIndex+1)
						if CurrentSlotEquipped == ItemDragged then
							SelectToolGui(PasteItemIndex,nil,true)
						end

					else
						table.insert(OwnedTools,PasteItemIndex,OwnedTools[ItemDragged])
						table.remove(OwnedTools,ItemDragged+1)
						table.insert(OwnedTools,ItemDragged+1,OwnedTools[PasteItemIndex+1])
						table.remove(OwnedTools,PasteItemIndex+1)
						if CurrentSlotEquipped == ItemDragged then
							SelectToolGui(PasteItemIndex,nil,true)
						end


					end

				end
			end

			ItemDragged = nil
		end
	end)
end

end

local function DragGui()
script.Parent.Template.Position = UDim2.new(0,mouse.X - 10,0,mouse.Y + 30)
end

local function upDateInventory()
for i,v in pairs(OwnedTools)do
if ScrollFrame:FindFirstChild(tostring(i)) == nil then
if i>9 and v ~= “” then
CreateButtonForTool(i,v)
end
else
if v ~= ""then
ScrollFrame:FindFirstChild(tostring(i)).ToolName.Text = v.Name
else
ScrollFrame:FindFirstChild(tostring(i)).ToolName.Text = “”
end
end
end
end

game:GetService(‘RunService’).Heartbeat:Connect(function()
upDateToolBar()
DragGui()
ToolParentChanged()
upDateInventory()
end)

I don’t know what I’m looking at. What do you want me to do exactly?

So i need the close/open button to be connected into the inventory frame gui
just like roblox default when u press it a quad key then it open the inventory
or when u click it by mouse on the button then it open or close

but idk how to connect to it

Connect a function to it that fires whenever the text button is clicked @PeacefulTobika already gave you a script to put in the button.

You can’t modify the keybind to open the Roblox backpack, it’s a CoreGUI. You’d need to make a custom backpack which I assume you’re already doing, in which case I’ve already provided a solution on how to make a toggleable GUI script.

So do you need to me add an local script inside the textbutton gui of it?

This is like the bare bones of scripting if you don’t understand this you should watch some more tutorials.

Do you know how to type the path to your inventory GUI? I will walk you through this but don’t expect others to do the same thing for something this simple.

Try this one in a local script in the gui

local button = -- path to your button here--
local Frame = -- path to your inventory frame here--

button.MouseButton1Click:Connect(function()
    Frame.Visible = not Frame.Visible
end)

Nope i dont i just need to add the button for the inventory gui by pressing keyboard and a mouse as well

I cannot look inside your game. I don’t know where exactly in the files the ScreenGUI and the Button is, so you need to do it yourself.

image

Drag the textbutton so that it’s parented to the Inventory ScreenGUI, let me know when you’ve done that.

alright the text button is inside the inventory gui

Okay, make a Local Script and make sure it is parented to the textbutton. Double click on the local script and paste the following code into it:

local Frame = script.Parent.Inventory

script.Parent.Activated:Connect(function()
    Frame.Visible = not Frame.Visible
end)

made by @Datsun4885, felt like I needed to state that

It should now be a button that toggles the inventory GUI to be on and off.

Where do you want me to put the local script inside of the textbutton or inside the inventory gui

Make sure it is parented to the textbutton.
Parented is another way of saying that it’s inside of an object. The TextButton would be the parent and the script would be the child of the parent.

“script.Parent.Activated”. use some common sense bro read the script ( too rude? )