Cannot access folder under local script, stored variable does not have folder object class; is userdata instead

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    The argument for the weapon parameter is a return from the previous checkWeapon() function that provides the value of a string value class. I want to make it so that I would be able to refer to a child folder in the local script with the weapon’s name and hence play the animations related to the weapon.

For some context, the character is a custom character with a left hand, right hand, left leg and right leg, and a torso.

  1. What is the issue? Include screenshots / videos if possible!
    I’ve narrowed the scope of the problem to this single part in which the WeaponAnimations variable is a userdata class instead of being a folder. Hence, when Play:() is triggered, it returns nil because it can’t find the animation.

It is not a typo, hierachy or previous code issue.


  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried FindFirstChild, WaitForChild

1 Like

I’ve tried weapon and tostring(weapon) for FindFirstChild() btw, same issue for both

This is referring to its Luau type which is different than a DataType or Class. In other words, folders (as well as Instance objects in general) are indeed userdata.


  1. you’re getting the checkWeapon() return from a StringValue using FindFirstChildOfClass() - are there other string values in the Player.RoundItems object? If so you may be returning the wrong value and your WeaponAnimations variable may be getting set to the wrong object.

  2. Could be a problem with server-client replication in which something only exists on the client and not the server, but it looks like this is all running in a LocalScript so seems less likely.

  3. You could use print statements or break points to see what values you’re actually returning and look for abnormalities to get a better idea of where things are going wrong.

Ultimately, you’re problem here is with finding objects in the data model. Without having a visual of said data model, or even knowing if you’re returning the correct values, its hard to know what factors could be at play / where things are going wrong.

I appreciate your reply, it was very informative. Folders are user data, didn’t know that.

The String Value is located in a folder as a child in the local player. There is only one string value throughout.

There is a client-server event in which the player buys the weapon and it appears as a child of the player in the form of an accessory. This is a separate procedure though, so it is unlikely to have been related to the issue.

I did use print to narrow the scope of the issue.
The checkWeapon() function works as intended. The possible issue is likely within the two blocks of AccessoryChecker() and gunmove().

Surprisingly though, it does work as intended for the first folder “AK47, but partially broken in which only the idle animation for the gun plays (along with Animation Track limit exceeded error) For the other folder “M16”, it returns a nil index issue for isPlaying().

Local Script


Animation Track Issue

M16 Issue

Okay, think I see the issue here;

You’ve bound the LoadAnimation() method to Runservice.Heartbeat and what this is doing is causing you to burn through the maximum amount of AnimationTrack objects that you can load into an Animator object (likely in just a few seconds of playtime assuming your running 30-60 FPS)

I can’t find any specific documentation at the moment, but presumably, when you hit the limit for animations, LoadAnimation() will stop returning an AnimationTrack object, and instead start returning nil which is causing your error.

I’m not going to rewrite the code since its all in screen shots, but you should change your code to only run LoadAnimation() once for each of your individual Animation objects, and then call Play() and Stop() on the respective AnimationTrack as needed. Lastly, binding to RunService is performance intensive and there are often better ways to accomplish the same goal without running a series of functions every frame, but the magic of it all is that you can do whatever it is you please with your own game :slight_smile:

1 Like

Thank you. I’ll use this as a reference for solving the problem.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.