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

PAYING | Roblox Studio | Stop repeating animation when key is off press?

local animations = {
				--Add your animations here like this format
				[Enum.KeyCode.W] = 1288223958,--Plays when "K" is pressed
	
	}



repeat wait() until game.Players.LocalPlayer; local player = game.Players.LocalPlayer
repeat wait() until player.Character; local character = player.Character
local currentAnimId,currentPlaying = '',nil
local humanoid = character:FindFirstChild('Humanoid')
local uis = game:GetService('UserInputService')

uis.InputBegan:connect(function(input,gpe)
	if not gpe then
		if animations[input.KeyCode] ~= nil then
			local animId = 'http://www.roblox.com/Asset?ID=' .. animations[input.KeyCode]
			if animId ~= currentAnimId then
				if humanoid ~= nil and humanoid.Health > 0 then
					if currentPlaying ~= nil and currentPlaying.IsPlaying then
						currentPlaying:Stop()
					end
					local animation = Instance.new('Animation'); animation.AnimationId = animId
					local animTrack = humanoid:LoadAnimation(animation); currentPlaying = animTrack
					animTrack:Play(0.100000001,1,1)
				end
			end
		end
	end
end)

So that's my script, it's a walking animation, but it carries on the animation even when i stop pressing "W". This is supposed to be easy? Please help me out,

Thank you, Aquascent.

2 comments

0

Have you read the rules? :)

1 answer

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