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

Animation on Keydown?

So hey! how do i make a LocalScript that all people can use when i press X i will do the Animation? Animation name is ExportAnim

Thanks for all Anwsers that are comming :)

  • kheng1

2 comments

0

I know how to make KeyDown Scripts but with a Animation i dont D;

0

I updated it

1 answer

✓ Accepted answer

So what you have to do it the following ~Make your keydown function

function onKeyDown(key)
	local Key = key:lower()
	if key == "r"  then

 --  (this is a localscript in the startergui by the way)

	end
end

Next what you want to do is to define your animations

local SprintAnim = Instance.new("Animation")
SprintAnim.AnimationId = "rbxassetid://425082298" -- Or whatever your animation is

Then when you want to play that animation you do this

mouse = Player:GetMouse() -- Get players Mouse
Player = game.Players.LocalPlayer
Character = Player.Character or Player.CharacterAdded:wait()
Humanoid = Character:WaitForChild('Humanoid')

local animationTrack = Humanoid:LoadAnimation(SprintAnim)
animationTrack:Play()

Now we put it together, your results are...

Player = game.Players.LocalPlayer
Character = Player.Character or Player.CharacterAdded:wait()
Humanoid = Character:WaitForChild('Humanoid')
local SprintAnim = Instance.new("Animation")
SprintAnim.AnimationId = "rbxassetid://425082298" -- Or whatever your animation is

function onKeyDown(key)
	local Key = key:lower()
	if key == "r"  then
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 * 2.5
		local animationTrack = Humanoid:LoadAnimation(SprintAnim)
		animationTrack:Play()
	end
end	


mouse.KeyDown:connect(onKeyDown) -- Call the function c:

HOPE THIS HELPED :D

4 comments

0

Hmm i tried to put the LocalScript in StarterGUI ,Workspace , StarterPack and still dont working

0

any errors in output?

1

You never fire the function, also, mouse.KeyDown is depreciated.

0

FIXED

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