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

Animation with keyDown, No tool?

Asked by
iKrale 0
10 years ago
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?id=187720963"

local Player = game.Players.LocalPlayer
local Mouse =  Player:GetMouse()
local animTrack = nil
local canPlay = true

Mouse.KeyDown:connect(function(key)
    if key == "q" then
        local player = game.Players.LocalPlayer.Character
        animTrack = player.Humanoid:LoadAnimation(animation) --Load the animation Senpai
        animTrack.KeyframeReached:connect(function(keyframeName)
        canPlay = true
        end)
    end
end)

Mouse.KeyDown:connect()

So confused on why it doesnt work e.o

1
Line 19 is not necessary, since you are not calling a function. TheeDeathCaster 2368 — 10y
0
Perhaps set a parent for "Animation." Also, I believe Roblox's Id format is this: "http://www.roblox.com/assets/?id=187720963" or "rbxassetid://187720963" Redbullusa 1580 — 10y

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

This doesn't work because you never play the animation. There are some other problems, however.

Line 19 is not needed. You used an anonymous function, so the connection is on line 09, when you create it.

There is no need for the canPlay variable because you have it set to true no matter what.

player is a bad name for that variable because the variable equals the character, not the player, which you already have a variable for.

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

local Player = game.Players.LocalPlayer
local Mouse =  Player:GetMouse()
local animTrack = nil

Mouse.KeyDown:connect(function(key)
    if key:lower() == "q" then
        local character = Player.Character
        animTrack = character:WaitForChild("Humanoid"):LoadAnimation(animation) 
        animTrack:Play()
    end
end)
Ad

Answer this question