Hi, i’m making a battlegrounds type game but to really help the players visualize what’s the “ultimate” move of the moveset, i need to order the moves.
Although i could set them in order, it wouldn’t work as my script finds what the player is using, then finding it in ServerStorage (where all the tools are located) which it is named the exact same within a folder, holding all the tools.
So how would i organize it so that tools are before others.
Such as
eg.
“Punch” as first
“Kick” as second
“Dropkick” as third
This script is located in a part in workspace
local ProximityPrompt = script.Parent
local spawns = workspace.Spawns:GetChildren()
local remote = game.ReplicatedStorage.Remotes.Music
ProximityPrompt.Triggered:Connect(function(plr)
local Character = plr.Character or plr.CharacterAdded:Wait()
local value = plr.leaderstats.Skill
local moveset = game.ServerStorage.SkillStorage:WaitForChild(value.Value)
if value.Value == "None" then
print("nuh uh!")
else
local spawnpoint = spawns[math.random(1, #spawns)]
local moves = moveset:GetChildren()
Character.HumanoidRootPart.CFrame = spawnpoint.CFrame
remote:FireClient(plr,"Music")
for i, v in pairs(moves) do
local clone = v:Clone()
clone.Parent = plr.Backpack
end
end
end)
Thank you for reading and i hope somebody can help me solve this mystery!
Hello, you can try this. If you have any questions make sure you ask!
--|< Variables >|--
local ProximityPrompt = script.Parent;
local spawns = workspace.Spawns:GetChildren();
local remote = game.ReplicatedStorage.Remotes.Music;
local movePriority = {
["Punch"] = 1,
["Kick"] = 2,
["Dropkick"] = 3,
-- Add more moves
}
--|< Connections >|--
ProximityPrompt.Triggered:Connect(function(plr)
local Character = plr.Character or plr.CharacterAdded:Wait();
local value = plr.leaderstats.Skill;
local moveset = game.ServerStorage.SkillStorage:WaitForChild(value.Value);
if value.Value == "None" then
print("Found no value.");
else
local spawnpoint = spawns[math.random(1, #spawns)];
local moves = moveset:GetChildren();
table.sort(moves, function(a, b)
local priorityA = movePriority[a.Name] or math.huge;
local priorityB = movePriority[b.Name] or math.huge;
return priorityA < priorityB;
end)
Character.HumanoidRootPart.CFrame = spawnpoint.CFrame;
remote:FireClient(plr,"Music");
for i, v in ipairs(moves) do
local clone = v:Clone();
clone.Parent = plr.Backpack;
end
end
end)
I haven’t made myself clear then,
i said that there’s mulitple moves and that it FINDS it in serverstorage, gathering all the movesets within the folder into the backpack. How would i sort this
@masterminyxs do you think you could explain the problem a bit better? I’m a bit confused by what you mean. From what you have said, it looks like @Mp3Alt has solved it as I can’t seem to find your issue if that isn’t it.
I’ll explain in more detail.
Do you know the strongest battlegrounds and how whenever you equip a character it would give you its moves? I’m trying to do that, well that’s all done.
But do you notice something else?
Their in a special order that always stays permanent.
My game does not have this. I would like to put some moves first and some at last to show which moves are the “Ultimate” of the kit.
I haven’t played strongest battlegrounds, but I get your general idea. Sorry, but it still does not really help - you are just reiterating what you previously said, but with an example. If you want to keep the tools, you should use a priority table paired with table.sort whenever the player respawns/changes character, pretty much just like @Mp3Alt said. You just clone all the tools, store them in a table, sort the table, and parent them to the backpack.
Can you explain what part of the system doesn’t work?
Nothing doesn’t work, i just want to organize the tools, ill just tell you in simpler terms.
So, if the player equips natural and goes to the cube to teleport, the game will find their skill value (which is natural) and give them their tools in this order:
What i want the order to be:
Blossom Snap
Thorning Branches
Terrority
Hold on a second, can’t i just use that table? Well, not exactly since this game isnt just based off one moveset. For example, we have another moveset called Explosive, exact same system but different moveset.
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. source of quotation
U can add attribute to tools represent their order and then insert them in order or by indexing to a table then, loop through that table and add tools to backpack.
function giveToolsInOrder(player, tools)
--Sort tools in order
table.sort(tools, function(toolA, toolB)
return (toolA:GetAttribute('Order') or 0) < (toolB:GetAttribute('Order') or 0)
end)
--Give the tools in order
for _, v in ipairs(tools) do
local newTool = v:Clone()
newTool.Parent = player.Backpack
end
end
make sure tools have attribute called “Order” set to number.