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 this animation play?

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

You have to write a . instead of :

 animtrack = player.Humanoid:LoadAnimation(animation)

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