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

How come my animation isnt playing when the tool is activated?

Asked by 9 years ago
-- Import animation
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=219254264"

-- Local variables
local animTrack = nil
local canPlay = true
local deb = false

function playGrabAnim(Source)
    if canPlay then
        local player = game.Players.LocalPlayer.Character
        canPlay = false
        animTrack = player.Humanoid:LoadAnimation(animation) -- Load animation into Humanoid
        animTrack.KeyframeReached:connect(function(keyframeName) -- Bind function to KeyframeReached event
    end)    
    end
end

script.Parent.Activated:connect(function()
    if deb == false then deb = true
        animTrack:Play()
    end
    wait(2)
    deb = false
end)

Also could you tell me how i would disable the arm from going up when the tool is equipped?

0
There's nothing wrong with that code, you should use it from a Server Script though. Goulstem 8144 — 9y
0
its within a tool though. AllianceScripter 30 — 9y
0
I know, but Animations won't display on the server if loaded from an instance created from the client. Goulstem 8144 — 9y
0
You'll have to access the player differently, and I suggest looking into RemoteEvents and ModuleScripts. Goulstem 8144 — 9y

1 answer

Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
9 years ago

Try using the Equipped Function instead of using Activated

-- Import animation
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=219254264"

-- Local variables
local animTrack = nil
local canPlay = true
local deb = false

function playGrabAnim(Source)
    if canPlay then
        local player = game.Players.LocalPlayer.Character
        canPlay = false
        animTrack = player.Humanoid:LoadAnimation(animation) -- Load animation into Humanoid
        animTrack.KeyframeReached:connect(function(keyframeName) -- Bind function to KeyframeReached event
    end)    
    end
end

script.Parent.Equipped:connect(function() -- see how I used the Equipped function.
    if deb == false then deb = true
        animTrack:Play()
    end
    wait(2)
    deb = false
end)

Ad

Answer this question