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

Why Won't this animation play?

Asked by 8 years ago

I am trying to put a script inside a tool so whenever i press the button "q", the animation plays. I have a script creating a forcefield in another local script in the same tool, but i am putting the animation in it's own local script so i don't get confused with all of the code. The error in this code keep saying "Global 'PlayForceAnim' is only used in the enclosing function; consider changing it to local" I have looked up so many guides of animation in roblox, but the one on the roblox wiki had the same code, except it said "PlayShockAnim" where "PlayForceAnim" is in my code. Please Help.

local tool = script.Parent

local animation = Instance.new("Animation")
            animation.AnimationId = "https://www.roblox.com/ForceField-Animation-item?id=429484416&rbxp=13961515"

            local animtrack =nil
            local canplay = true


tool.Equipped:connect(function(mouse)
    mouse.KeyDown:connect(function(key)
        if
            key =="q" then
            function PlayForceAnim(Source)
                if
                    canplay then
                    local player = game.Players.LocalPlayer.Character
                    canplay = false
                    animtrack = player.Humanoid.LoadAnimation(animation)
                    animtrack.keyFrameReached:connect(function(keyFrameName)
                        if
                            keyFrameName == "ForceEnd" then
                            canplay = true
                        end
                    end)
                    animtrack:Play()
                end
            end 
        end
    end)
end)

1 answer

Log in to vote
0
Answered by
Bertox 159
8 years ago

You have to write a . instead of :

 animtrack = player.Humanoid:LoadAnimation(animation)
Ad

Answer this question