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

I need a piece of code that can help in an animation ?

I need a piece of code that when u spam the key (In my case e) It only plays until it finishes.

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid

local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=03836741039"

mouse.KeyDown:connect(function(key)
	if key == "e" then
		local playAnim = humanoid:LoadAnimation(anim)
		playAnim:Play()
	end
end)

1 comment

0

you could posibly wait the amount of time the animation takes

1 answer

✓ Accepted answer

Check when the animation track isPlaying property is true

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid

local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=03836741039"
local UserInputService = game:GetService("UserInputService")
animationTrack = humanoid:LoadAnimation(anim)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then

		if(input.KeyCode == Enum.KeyCode.E)then
			if(not animationTrack.IsPlaying)then
				animationTrack:Play()
			end
		end
	end
end)

1 comment

0

Thank you

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