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

Arrange the order of the tools in a player's backpack?

Asked by 6 years ago

Is there a way to set the order of the tools in a player's backpack via a script?

0
You didn’t specify how you want the tools to be sorted. By name? Type? Damage? T0XN 276 — 6y
0
If you’re going to ask a question on this website, I’d expect some effort put into the question so I know what you’re looking for T0XN 276 — 6y
0
What have you tried already.? T0XN 276 — 6y
0
the question is clear, do you have any constructive info to offer on the matter, T0XN Nonaz_jr 439 — 6y

2 answers

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
6 years ago

Tools are sorted by the order they arrive to the backpack, then manually if chosen. So your best option would be to remove all tools then instantly parent them back in the order you want. For example, alphabetical order:

local tools = player.Backpack:GetChildren()
for _,v in ipairs(player.Character:GetChildren()) do
    if v.ClassName=="Tool" then
        tools[#tools+1]=v
    end
end
table.sort(tools,function(a,b) return a.Name<b.Name end)
for _,t in ipairs(tools) do t.Parent=nil end
wait()
for _,t in ipairs(tools) do t.Parent=player.Backpack end

For anything better you gotta make a custom backpack

0
Thanks! Le_Teapots 913 — 6y
Ad
Log in to vote
0
Answered by
Nonaz_jr 439 Moderation Voter
6 years ago

I would like to know too if there is a good way.

But yeah, all I can think of, is to remove all items and add them one by one in the order you want. :P

0
Why would you put this as an answer then? T0XN 276 — 6y
0
because it sets the order of the tools in a player's backpack via a script. why would you put this as a comment? Nonaz_jr 439 — 6y
0
You could probably GetChildren() the backpack, .Parent=nil the tools, sort the table with table.sort and then parent them back. optiplex123 21 — 6y

Answer this question