Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Animation on Keydown?

Asked by
kheng1 10
8 years ago
Edited 8 years ago

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
0
I know how to make KeyDown Scripts but with a Animation i dont D; kheng1 10 — 8y
0
I updated it NetworkMan243 65 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

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

0
Hmm i tried to put the LocalScript in StarterGUI ,Workspace , StarterPack and still dont working kheng1 10 — 8y
0
any errors in output? NetworkMan243 65 — 8y
1
You never fire the function, also, mouse.KeyDown is depreciated. theCJarmy7 1293 — 8y
0
FIXED NetworkMan243 65 — 8y
Ad

Answer this question