Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make the backpack invisible, but still have access to the tools?

I need help, I know how to make the backpack invisible, but I don't know how to still be able to use the tools.

local StarterGui = game:GetService('StarterGui')

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

1 answer

Hi iiCookieCrisp_YT,

I have been working on this for like the past hour now and have finally come to a sustainable solution. The script that I made is simple, efficient, and easy to edit so, I am happy to share it with you. I will just get into the script because it's easier to do it that way. First thing you should know is the hierarchy of the whole thing. This is how the hierarchy looks. So, let's get into it.


####Script

local players = game:GetService("Players"); -- Players Service where all the players are.
local player = players.LocalPlayer; -- Local Player, the one that is interacting with the script.
local bp = script.Parent; -- The Backpack.
local uis = game:GetService("UserInputService"); -- UserInputService
local tools = bp:WaitForChild("Tools"); -- The tools folder where the backpack tools are, from 1 - 10.
local tool_children = tools:GetChildren(); -- The table with all the tools in it.
local now = nil; -- The tool that the character has now, it's nil for now because nothing has been equipped yet.

local keys = { -- All of the keys, this is used to make the function only run if the Backpack keys are used
	["One"] = true;
	["Two"] = true;
	["Three"] = true;
	["Four"] = true;
	["Five"] = true;
	["Six"] = true;
	["Seven"] = true;
	["Nine"] = true;
	["Eight"] = true;
	["Zero"] = true;
}

local key_num_translation = { -- Translation so that you can access the tool for each key pressed. Since tables go from 1 - n, n being the total amount of objects in the table.
	["One"] = 1;
	["Two"] = 2;
	["Three"] = 3;
	["Four"] = 4;
	["Five"] = 5;
	["Six"] = 6;
	["Seven"] = 7;
	["Nine"] = 8;
	["Eight"] = 9;
	["Zero"] = 10;
}

uis.InputBegan:Connect(function(key, gp) -- Anonymous function with gp and key, which are the parameters for the function.
	if keys[key.KeyCode.Name] and not gp then -- Checks if the key is one of the ones used to get tools from the backpack, so the number pad basically.
		local char = player.Character or player.CharacterAdded:Wait(); -- Character of the local player
		local num = key_num_translation[key.KeyCode.Name]; -- The number to access the tool from the table. So, you're translating from what you pressed to a number that can index the tool from the table.
		local tool = tool_children[num]; -- The tool indexed from the above number, basically the tool that you got from the backpack.
		
		if now then -- Checks if 'now' exists.
			now.Parent = tools; -- Makes the now's parent tools.
		end -- end for the checking of 'now'.
		
		if tool and now ~= tool then -- Checks if the tool exists and if 'now' is not the tool, basically to detect if you're not pressing the same button again.
			tool.Parent = char; -- Makes the tool's parent the character, which you need to do to make the tool equipped.
			now = tool; -- Makes now the tool because you've just equipped it.
		elseif now == tool then -- if 'now' is the tool, which means that you just pressed the same button again.
			now = nil; -- It will set now to nil because you put it back into the tool folder.
		end -- end for checking if tool exists and if 'now' is not the tool.
	end -- end for checking if the number pad keys are pressed.
end) -- end for the whole anonymous function.

##Well, I hope I helped and have a nice day/night.

Thanks,

Best regards,

~~ KingLoneCat

1 comment

0

KingLoneCat, where does this script go and is it a local or a regular?

This discussion is preserved as it was. New answers, comments, and votes are closed.