String format does't match with existing instance

Hey everyone!

I don’t think the title is relevant so let me explain.

I’m making a StarterCharacter system and I made a module that returns the data of the animations.

--> Module: 
return {
	['Idle1'] = '507766388'; --> Idle 1
	['Idle2'] = '507766388'; --> Idle 2
	['Walk'] = '507766388'; --> Only mobile and speed modifier
	['Run'] = '507766388';
	['Jump'] = '507766388';
	['Fall'] = '507766388';
	['Climb'] = '507766388';
--> Require:
local animationsData = require(Data.animationsData)

At this point, I loop all the animations one by one with the key and the animationId.

for name, animationId in pairs(animationsData) do

After this, I use a pcall function to verify the animation. it is working so I will not speak about the sample of code. It returns if the animation exists and the data of the asset.

And then I look for the animation in the char’s animate script.
To achieve this, I have to format my string. The first thing is to find the Value in the animate script: image

So it is easy to find it cuz it the key of my dictionary so I just do:


Then I just look for the animation instance in the value, adding an ‘Anim’ string.
So here is the path:

animate[lower(name)][name..'Anim'] --> Exemple for Walk = 'animId': animate['walk']['WalkAnim']

So basically, it works. It found my animations.
But the problem is for the Idle animations. It is split into two animations, a basic one and a longer one:
So the name of the Idle animations are ‘Idle1’ and Idle2’:

So I add a or after the first path for "normal’ animations and started to format my string to have the path to the two animations.
Here is the first string (it has to be ‘idle’) and the second one (it has to be ‘Animation1’ or ‘Animation2’)

local string1 = lower(sub(name, 1, 4)) --> 'Idle1' -> 'idle'
local string2 = 'Animation'..sub(name, 5, 5) --> 'Idle1' -> 'Animation1'

So I just print the virtual path and the path I’m looking for:


--> Output:

So, they match.
Now, I just return my animation, and here is the final line of code:

return animate[lower(name)][name..'Anim'] or animate[string1][string2]

When I run the game, I have the returned error:

--> Ouput:
'idle1 is not a valid member of LocalScript "Workspace.Padrox_x.Animate'

So I’m confused. Why does it look for ‘idle1’ if string1 is ‘idle’.

Any help would be appreciated.
Thank you in advance.

1 Like

you said the names of the animations are “Idle1” and “Idle2”. if that’s the exact error copy and pasted, you might have a capitalization error somewhere.

It was an easy fix. I was trying to get the value of the first path, so it attempted to find string2 with a nil result from string1. So I just split it into two declarations.
The first one for the to find the animationValue and the second one if the animationValue was found before.

local animationValue = animate:FindFirstChild(lower(name)) or animate:FindFirstChild(lower(sub(name, 1, 4)))
				if animationValue then
					return animationValue:FindFirstChild(name..'Anim') or animationValue:FindFirstChild('Animation'..sub(name, 5, 5)) or animationValue:FindFirstChild(name)
					return false
1 Like