Not a valid member of ModuleScript


Hello I’m currently trying to find a way to store animations, using animationId’s and referencing the animations through an table using (ModuleScript) which will load the animations to the character at a specific event through local script called Animate in StarterCharacterScripts.
I keep receiving (Walk is not a valid member of ModuleScript “ReplicatedStorage.AnimationsTable”)
Puzzled, and not sure how to fix it. Bellow is the script. I used the Assistant AI in to help me learn how to script along with documentation as well. by the way, no errors, warnings, reports, or hints were visible in the Script Analysis.

(Module Script)

local AnimationTablemodule = {
[“Walk”] = “rbxassetid://15791500540”,
[“Jump”] = “rbxassetid://15779173308”
}

return AnimationTablemodule

(Local Script)

–local humanoid
local humanoid = script.Parent:WaitForChild(“Humanoid”)
–where replication storage is
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
–refernce to animation table
local AnimationTable = ReplicatedStorage:WaitForChild(“AnimationsTable”)
–humanoid instance
local humanoid = script.Parent:WaitForChild(“Humanoid”)

local function playAnimation(animationId)
local animation = Instance.new(“Animation”)
animation.AnimationId = animationId

local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()

end

local function stopAnimation()

for _, animationTrack in pairs(humanoid:GetPlayingAnimationTracks()) do

	animationTrack:Stop()

end

end

humanoid.Running:Connect(function(speed)

if speed > 0 then

	playAnimation(AnimationTable["Walk"])

else

	stopAnimation()
end

end)

humanoid.Died:Connect(stopAnimation)

You’re not using the require function:

local AnimationTable = require(ReplicatedStorage.AnimationsTable)
1 Like

Since you weren’t using the require function, it was thinking that you were trying to get a child with the name of “Walk” from the module AnimationsTable.

What using the require function does is that it makes it so that it returns the actual table in the module (AnimationTablemodule) instead of returning the ModuleScript

Thanks animations works when speed > 0, animation stops when < 0.

1 Like

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