Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Calling animations stored in a table?

Asked by
Chronomad 180
8 years ago

I have a set of animations defined and then stored in a table as,

local Left = Instance.new("Animation")
    Left.AnimationId = "rbxassetid://416628708"
    local Right = Instance.new("Animation")
    Right.AnimationId = "rbxassetid://416628708"
    local Forward = Instance.new("Animation")
    Forward.AnimationId = "rbxassetid://312976450"
    local Backward = Instance.new("Animation")
    Backward.AnimationId = "rbxassetid://312976450"
    local Jump = Instance.new("Animation")
    Jump.AnimationId = "rbxassetid://312976450"
    local Idle = Instance.new("Animation")
    Idle.AnimationId = "rbxassetid://416928266"

local Inputs = {Left,Right,Forward,Backward,Jump,Idle}

However, when I try to play the animations from the table, I get this error.

21:23:34.337 - Argument error: must be an Animation object

Is there any way around this issue? Thanks for any help. Full script below


--Player Variables-- local Left = Instance.new("Animation") Left.AnimationId = "rbxassetid://416628708" local Right = Instance.new("Animation") Right.AnimationId = "rbxassetid://416628708" local Forward = Instance.new("Animation") Forward.AnimationId = "rbxassetid://312976450" local Backward = Instance.new("Animation") Backward.AnimationId = "rbxassetid://312976450" local Jump = Instance.new("Animation") Jump.AnimationId = "rbxassetid://312976450" local Idle = Instance.new("Animation") Idle.AnimationId = "rbxassetid://416928266" local already_ran = false local grounded = false local State = false local P = game:GetService('Players').LocalPlayer repeat wait() until P.Character local Inputs = {Left,Right,Forward,Backward,Jump,Idle} --local Event = game.ReplicatedStorage.Events:WaitForChild("AnimationEvent") local Value function onKeyPress(inputObject, gameProcessedEvent) --if State == true then if inputObject.KeyCode == Enum.KeyCode.A then Value = Inputs[1] elseif inputObject.KeyCode == Enum.KeyCode.D then Value = Inputs[2] elseif inputObject.KeyCode == Enum.KeyCode.W then Value = Inputs[3] elseif inputObject.KeyCode == Enum.KeyCode.S then Value = Inputs[4] elseif inputObject.KeyCode == Enum.KeyCode.Space then Value = Inputs[5] else Value = Inputs[6] end end game:GetService("UserInputService").InputBegan:connect(onKeyPress) P.Character.Humanoid.Running:connect(function(speed) for _,v in pairs(P.Character.Humanoid:GetPlayingAnimationTracks()) do v:Stop(0) end if speed < 1 then local AnimTrack = P.Character.Humanoid:LoadAnimation(Value) AnimTrack:Stop() wait(.01) AnimTrack:Play() print("Idle and Awaiting Input") State = false elseif speed > 0 then local AnimTrack = P.Character.Humanoid:LoadAnimation(Value) print("Moving") AnimTrack:Stop() wait(.01) AnimTrack:Play() State = true end end)

Answer this question