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

Why won't the animation play when the player presses F?

I don't know too much about animations sooo idk what I did wrong

game.Players.PlayerAdded:Connect(function(plr)
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.F then
		local animation = Instance.new("Animation")
animation.AnimationId = "3560009028"
local animTrack = nil
local canPlay = true
 
function playShockAnim()
    if canPlay then
        local player = plr
        canPlay = false
        animTrack = player.Humanoid:LoadAnimation(animation)
        canPlay = true
        animTrack:Play()
    end
end
 
playShockAnim(plr)
	end
end)
end)

2 comments

0

idk man

0

What's the error message?

1 answer

Ok so your formatting is a little confusing but when a rearranged it, it looks like this

game.Players.PlayerAdded:Connect(function(plr)
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.F then
		local animation = Instance.new("Animation")
		animation.AnimationId = "3560009028"
		local animTrack = nil
		local canPlay = true
	
		function playShockAnim()
			if canPlay then
	       	 	local player = plr
	        	canPlay = false
		        animTrack = player.Humanoid:LoadAnimation(animation)
	        	canPlay = true
	       		animTrack:Play()
			end
		end
		playShockAnim(plr)
	end
end)
end) -- extra end)?

I don't understand why you have a function defined when the player presses f instead of just doing what the function does. The real problem is that the animation ID should be "rbxassetid://3560009028" instead of just "3560009028", which is probably why your animation isn't playing, also you should make your animation priority higher so it doesn't get interupted by movement animations.

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