Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How come my animation isnt playing when the tool is 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.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?

4 comments

0

There's nothing wrong with that code, you should use it from a Server Script though.

0

its within a tool though.

0

I know, but Animations won't display on the server if loaded from an instance created from the client.

0

You'll have to access the player differently, and I suggest looking into RemoteEvents and ModuleScripts.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.