Can't use GetChildren() in a Module?

For some reason, GetChildren() is returning nothing within my Module Script, it should be returning the animations stored within the “Animations” folder, but it doesn’t seem to be doing that. Does anyone know why this issue is the way it is, and how I can fix it?

I’ve been looking around the Devforum for a while, and checking the developer hub, but I can’t find a solution.

MODULE SCRIPT

local AnimationsModule = {}

local Storage = game.ServerStorage.Animations
local AnimationStorage = {}

-- | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | --

-- This Function loads in the animations into a character the moment that it is called.
function AnimationsModule:LoadAnimations(Player)
	
	-- Test Stuff --
	print (Player)

	-- Script Variables --
	local Char = Player.Character
	local Humanoid = Char.Humanoid

	-- Checks if the Player has an 'Animation' Account, if they do not, it creates one.
	if AnimationStorage[Player.UserId] == nil then
		
		AnimationStorage[Player.UserId] = {}
	
	end

	-- Script --

	for i, Animation in pairs(Storage:GetChildren()) do
		
		print ("YO! TEST! TEST!")
	   	print (Animation.Name)
		 AnimationStorage[Player.UserId][Animation.Name] = Humanoid:LoadAnimation(Animation.AnimationId)
		

	end

	print (AnimationStorage)

end

-- | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | --

-- Testing Animation
function AnimationsModule:PlayAnimation(Player)

	print(AnimationStorage[Player.UserId])
	print (Storage:GetChildren())
	print (Storage.Squat)
end

return AnimationsModule

For further context, I’m basically trying to load in Animations ahead of time since I’ve ran into a few issues, where I load the animation within the wrong scope and it’s loaded several times. This prevents me from properly manipulating the animation in the future.

The ‘Animations’ folder within my ServerStorage contained two Animation instances “Squat” and “SquatIdle”, but neither seem to pop up.

Help would be appreciated! :sweat_smile: :pray:

(If additional information is needed, ask and I will show!)

1 Like

Is this module being required by a LocalScript? If so, they don’t have access to the contents of ServerStorage - they don’t replicate to the client. You’d have to use ReplicatedStorage if you wanted the program to access the animations via a LocalScript.

2 Likes

No, it’s not a Local Script, that’s the confusing part honestly, I can’t really piece together why it’s not working.

SERVER SCRIPT

-- Variables --

local Remote = game.ReplicatedStorage.TestRemote2
local PlayerData = require(game.ReplicatedStorage.PlayerData)
local Animations = require(game.ServerStorage.Animations)
local CountDown = nil


-- Function --



-- Script --

Remote.OnServerEvent:Connect(function(Player)
	
	local UserID = Player.UserId
	
	Animations:LoadAnimations(Player)
	Animations:PlayAnimation(Player)
	
end)

This is the server script paired up with the Module Script, I just press Num Pad 1 and it fires it, it’s kind of a testing script

1 Like

I’m taking a shot in the dark with this, but what happens if you replace the semicolons for Animations with dots?

function AnimationsModule.PlayAnimation(Player)
...
Animations.PlayAnimation(Player)
2 Likes

It’s still printing as nil for line 46 and 47. That shouldn’t be happening right?

Output - Roblox Studio (gyazo.com)


This is what I have in server storage
Server Storage - Roblox Studio (gyazo.com)

1 Like

Why is it nil? It looks like it should be working. Did you make a syntax error somewhere?

1 Like

Don’t know man . . .

:frowning_face:

The struggle is real out here . . I think I might be stuck with another 12 hour problem that’s just a super easy fix.

1 Like

So these 2 lines return {} or nil? Or is it the :LoadAnimation() function?

2 Likes

rename either the module script or the folder my guess is its grabbing the script named “Animations” and getting the children of that

2 Likes

It returns {}, I will try to rename them!

1 Like

Are you really sure that you are accessing the right folders and that these folders actually have the animations in them? Check it again please.

2 Likes

Does this print anything? {30_Chars}

2 Likes

My script got a bunch of bugs because there’s something wrong with it, but the error I made the post for is fixed! Thank you, I didn’t know it’d be something like that!

pepo

You’re the goat bro. I’m going to write this down into one of the bugs that happen with roblox so it doesn’t happen again

1 Like

Yes, and thank you for the assistance, now I’m running into a diffrent problem, but I’ll make a diffrent post if I can’t fix it

1 Like

Wait so what was the bug, was it the animations not being in the folder or were you accessing the wrong folders? If so then it’s not a roblox bug.

2 Likes

Make sure to notify me (@Sougood) in that post so I know when you need help!

2 Likes

I meant to reply to the other guy, you just both had similar icons, that’s my bad. The problem was with the name of the folder for some reason

(And thank you!)

2 Likes