Hi,
I’ve been trying to script a script for an emotes gui but then I ran into a problem. I realised I had 27 animations and I want to get the number from the name so if you click on an emote button it will find the next animation in order.
Thanks,
Alek
Can you please explain a bit more but what do you mean by getting the number from the name?
Name of what and what number?
I have a folder of animations named animation1, animation2 etc. and I want to make an automatic system that finds they’re number.
If you’re trying to systematically index the animations, finding the animation with the name animation .. index
should work. However, it seems rather impractical considering how you are going to distinguish the animations in the future.
You can split the string into 2 separate ones.
local str = string.split("animation1", "animation")[2] -- // This will seperate 'animation1' into 2 pieces, sepearating string is the second argument. Will return '1'.
str = tonumber(str) -- // Convert the string '1' into a Number.
There are several other methods to use, but this is the simplest one.
Can you make this print all of them?
You could go about this in multiple ways, but if you’re going by name then this would probably be most practical.
local Animations = AnimationsLocation:GetChildren()
table.sort(Animations,
function(a,b)
return string.gsub(a.Name, "%D", "") < string.gsub(b.Name, "%D", "")
end)
for _,v in pairs(Animations) do
print(v)
end
That should do it. ^
Do you want a system that finds their number - Like animation1 = 1 , first animation?
To sort the animations by their number
Oh!!! it can be from lowest to highest, it’s your choice. Easily made with table.sort()
My bad I fixed it. it is a.Name and b.Name.
Looks pretty good to me , well done.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.