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

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

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 comment

1

Please put your code in a code block.

1 answer

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.

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