I’ve been rewriting my rig script for a while now and I encountered a problem that might be simple to fix. What I’m attempting to create is a smaller script that preloads all the animations and can play a specific animation when requested.
I have the loop written down so that it does load the animations to a rig, but I can’t figure out a way to actually play the animations without directly making a variable then playing it… Is there a method, or is this not viable at all and I would have to load each and every animation with a variable to play them?
I also thought about using like nested tables to achieve this, but still. Any help would be greatly appreciated. Willing to provide more script information if needed.
New Animation Loading function.
local function SetupRigAnimations(Player, P1P2)
-- First grab the Animation set thats EQUIPPED from Player.
local AnimSet = Main.Inv_CheckPlrItemValue(Player.Name, "DevelopmentSet" .. P1P2, "EQUIPPED")
local Data = AnimSet:GetChildren()
local Rig = game.Workspace.PlayerRigs:FindFirstChild(Player.Name, true)
for i = 1, #Data do
local Anim = Instance.new("Animation")
Anim.AnimationId = tostring(Data[i].Value)
print(Anim.AnimationId)
Rig.Humanoid.Animator:LoadAnimation(Anim)
print("Animation loaded successfully:", Data[i], ", for:", P1P2)
end
end
Old version which played animations:
P1StandingIdle.AnimationId = "rbxassetid://16715749873"
P1WalkForward.AnimationId = "rbxassetid://16804478030"
P1WalkBackward.AnimationId = "rbxassetid://16804479545"
P1Crouching.AnimationId = "rbxassetid://16804481184"
P1CrouchingIdle.AnimationId = "rbxassetid://16804485315"
P1DashtoDive.AnimationId = "rbxassetid://16804484183"
P1DashStart.AnimationId = "rbxassetid://16804602501"
P1Dashing.AnimationId = "rbxassetid://16804604281"
P1DashEnd.AnimationId = "rbxassetid://16804603477"
P1Prone.AnimationId = "rbxassetid://16890382796"
-- Player 2
-- Loads animations
local P1StandingIdleTrack = P1Rig.Humanoid.Animator:LoadAnimation(P1StandingIdle)
local P1WalkForwardTrack = P1Rig.Humanoid.Animator:LoadAnimation(P1WalkForward)
local P1WalkBackwardTrack = P1Rig.Humanoid.Animator:LoadAnimation(P1WalkBackward)
local P1CrouchingTrack = P1Rig.Humanoid.Animator:LoadAnimation(P1Crouching)
local P1CrouchingIdleTrack = P1Rig.Humanoid.Animator:LoadAnimation(P1CrouchingIdle)
local P1DashtoDiveTrack = P1Rig.Humanoid.Animator:LoadAnimation(P1DashtoDive)
local P1DashStartTrack = P1Rig.Humanoid.Animator:LoadAnimation(P1DashStart)
local P1DashingTrack
local P1DashEndTrack = P1Rig.Humanoid.Animator:LoadAnimation(P1DashEnd)
local P1ProneTrack = P1Rig.Humanoid.Animator:LoadAnimation(P1Prone)
-- This will just run off the side for now but will be loaded in once we get lobbies setup
P1StandingIdleTrack = P1Rig.Humanoid.Animator:LoadAnimation(P1StandingIdle)
P1StandingIdleTrack:Play()