I made a custom toolbar it works and all, but I’m trying to add a hot key button that is according to the sort order it it’s… There is a LayoutOrder that I think would be the easiest way to do this…
But here’s my Idea, not sure how to execute it…
Every time a tool gets added it gets a specific Layout Order
Oldest → Newest…
But depending if say you had 3 tools and it removes 2, 1 and 3 would remain the same…
My question:
How do I add the specific layout order every time a new tool is added, 1st Tool → LayoutOrder 1, 2nd Tool → LayoutOrder 2, and so one…
Then how would I fix the numbers so if a number was removed the order 1-9 is not ruined.
This will be used for KeyCodes like I states… So looking into Enum.KeyCode…
The keyboard numbers are actually the full name
“Zero”, “One”, “Two”… how would I tell that 1 = “One” and so on.
This is a very open question so I will try my best to give you ideas.
But depending if say you had 3 tools and it removes 2, 1 and 3 would remain the same…
Not sure what you mean by that, so I will not comment on it.
Try setting custom positions yourself, positions for 1 tool, 2 tools, and so on. Then have a folder or something for each tool (tool in slot 1, slot 2, etc). Have like a counter or something to see how many tools there are. Use the KeyCodes to open the correct tools, now that you have full control over them should be easy.
What instantly came to mind for me when reading this is using a table, then using table.insert and table.remove every time a tool is added or removed, and using that table to organize which tool is 1, which is 2 and so on…
I assume what you want to achieve is having an organized set of tools set to specific numbers, so one tool is number 1, another is 2… This also applies to (“Oldest → Newest”).
By using table.remove the table should automatically re-position the variables so that 3 becomes 2 and 4 becomes 3, etc.
An example of adding a child to the table while it remains organized:
An example of removing a child from the table while it remains organized.
First I would have the localscript keep track of my tool table:
function ToolAdded(Tool)
if Tool:IsA("Tool") then
table.insert(ToolTable, Tool.Name)
end
end
function ToolRemoved(Tool)
if Tool:IsA("Tool") then
local Count = 0
for i,tools in pairs(ToolTable) do
Count = Count + 1
if tools.Name == Tool.Name then
table.remove(ToolTable, Count)
end
end
end
end
Backpack.ChildAdded:Connect(ToolAdded)
Backpack.ChildRemoved:Connect(ToolRemoved)
Note that I use the instances ChildAdded and ChildRemoved to detect each event, then adds/removes from the table accordingly. Instance.ChildAdded Instance.ChildRemoved
Now that we have the ToolTable constantly updated, we can keep track of UserInputService:
function KeyPressed(Key, gameProcessed)
if not gameProcessed then
if Key.KeyCode == Enum.KeyCode.One then
-- Equip table[1] FROM SERVER SIDE USING REMOTEEVENT
elseif Key.KeyCode == Enum.KeyCode.Two then
-- Equip Table[2] FROM SERVER SIDE USING REMOTEEVENT
end
end
end
InputService.InputBegan:Connect(KeyPressed)
Here I say that each KeyCode from UserInputService each equips a tool from the tool table on server side, there is probably a better way of doing this rather than defining each table child, however I assume there wouldn’t be too many.
Keep in mind you also have to parse through at least the tool as an argument so the server knows which tool to equip. You use the server side to equip the tools if you want it to replicate, otherwise it won’t.
The whole localscript:
Keep in mind this would need more work to actually function, however I am just going into the basics of how you could possibly do this.
repeat wait() until game.Players.LocalPlayer.Character
local InputService = game:GetService("UserInputService")
local PS = game:GetService("Players")
local LP = PS.LocalPlayer
local Backpack = LP:WaitForChild("Backpack")
local ToolTable = {}
function ToolAdded(Tool)
if Tool:IsA("Tool") then
table.insert(ToolTable, Tool.Name)
end
end
function ToolRemoved(Tool)
if Tool:IsA("Tool") then
local Count = 0
for i,tools in pairs(ToolTable) do
Count = Count + 1
if tools.Name == Tool.Name then
table.remove(ToolTable, Count)
end
end
end
end
function KeyPressed(Key, gameProcessed)
if not gameProcessed then
if Key.KeyCode == Enum.KeyCode.One then
-- Equip table[1] FROM SERVER SIDE USING REMOTEEVENT
elseif Key.KeyCode == Enum.KeyCode.Two then
-- Equip Table[2] FROM SERVER SIDE USING REMOTEEVENT
end
end
end
InputService.InputBegan:Connect(KeyPressed)
Backpack.ChildAdded:Connect(ToolAdded)
Backpack.ChildRemoved:Connect(ToolRemoved)
If you have any questions regarding my script, feel free to message me.
So after testing, the items automatically get added to the keybinds but the same issue still exists that say Tool2 Is removed then Tool1 and Tool3 still remains at the same keybind
It’s better to check for ChildAdded in the player’s character, as whenever you equip a tool, it goes out of the backpack and into a player’s character in the workspace lol. Otherwise good job :>