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

How do I play a animation when I press a a certain key?

Asked by 8 years ago
Edited 8 years ago

I tried to make a animation play by pressing Q. Nothing happened. Can you guys help me out?

local UserInputService = game:GetService("UserInputService") local localPlayer = game.Players.LocalPlayer

local animation = Instance.new("Animation") animation.AnimationId = "http://www.roblox.com/Asset?ID=492283384"

01local animTrack = nil
02local canPlay = true
03 
04local function onInputBegan(input, gameProcessed)
05    if input.UserInputType == Enum.UserInputType.Keyboard then
06        local keyPressed = input.KeyCode
07        if keyPressed == Enum.KeyCode.Q then
08    local player = game.Players.LocalPlayer.Character
09        canPlay = false
10        animTrack = player.Humanoid:LoadAnimation(animation) -- Load animation into Humanoid
11        animTrack.KeyframeReached:connect(function(keyframeName) -- Bind function to KeyframeReached event
12            if keyframeName == "ElectrocuteEnd" then
13                canPlay = true
14end
15 
View all 36 lines...
0
That's a free model script though... Seraine 103 — 8y
0
No. It's not. Milestmnt 5 — 8y

1 answer

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

You can use this instead its not mine so i wont use it for my game ;p

01     Animation = Instance.new("Animation")
02    Animation.Parent = game.Workspace
03    Animation.AnimationId = "http://www.roblox.com/asset/?id=ID HERE" --Where It Says ID HERE, Place Your Animation Id
04    local Player = game.Players.LocalPlayer
05    local mouse = game.Players.LocalPlayer:GetMouse()
06mouse.KeyDown:connect(function (key)
07    for i, v in pairs(game.Players:GetChildren()) do
08    if key == "f" then -- THIS IS UR KEY U WANA CHANGE IT CHANGE F TO SOMETHING ELSE
09        local AnimationTrack = Player.Character.Humanoid:LoadAnimation(Animation)
10            AnimationTrack:Play()
11    end
12    end
13    end)

That is all ;)

Dont forget to accept my answer

Ad

Answer this question