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

Trying to make it where you press a key to play animation?

Asked by 9 years ago

Why won't this work, I'm trying to make it where you press a key to play the animation?????

local Anim = script:FindFirstChild("AnimationHolder") local RunAnim = Anim:FindFirstChild("Atease")--name of animation id in it local t = game.Players.LocalPlayer.Humanoid local mouse = game.Players.LocalPlayer:GetMouse()

mouse.KeyDown:connect(function(key)

if key == "z" then t.RunAnim:Play() t.WalkSpeed = "26" end end)

1
Please put your code in a code block. yumtaste 476 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

The problem is that you aren't loading the animation. You need the load the animation using a function called :LoadAnimation(). You use this function on the humanoid.

workspace.Player1.Humanoid:LoadAnimation(00000) --Animation id.

Another problem is variable t. For the humanoid is not in the Player but in the Character. You should also use :FindFirstChild() to find the humanoid and also check if it exists.

if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") then --If the humanoid exists then
    print("We found a humanoid!")
end

Output:

We found a humanoid!


Another problem is the walkspeed. WalkSpeed is a NumberValue not a string. So no "quotes" or 'these' or [[double square brackets.]]


Finished product:

local Anim = script:FindFirstChild("AnimationHolder")
local RunAnim = Anim:FindFirstChild("Atease")--name of animation id in it
local t = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
local mouse = game.Players.LocalPlayer:GetMouse()
local Animation = t:LoadAnimation(RunAnim)

mouse.KeyDown:connect(function(key)
    if key.lower() == "z" and t then --Use lower incase their capslock is on. Notice the "and".
        Animation:Play()
        t.WalkSpeed = 26 --WalkSpeed is a numbervalue, not a string.
    end
end) --Use code block next time.
Ad

Answer this question