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

Am i doing this custom animation rig keybind correct?

Trying to come up with a script that plays an animation once "q" is pressed, not seeming to work... Is anything wrong?

Should i be doing it differently?

local Player = game.Players.LocalPlayer
local Animation = Instance.new("Animation",script)
Animation.AnimationId = "483517771"
local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(Input)
 if Input.KeyCode == Enum.KeyCode.Q then
  local NewAni = Player.Character.Humanoid:LoadAnimation(Animation)
  NewAni:Play()
 end
end)

end)

When i do press q, the output gives me "00:30:39.265 - Animation failed to load : Players.Erythia.PlayerGui.LocalScript.Animation"

Any help or advice would be great, thanks!

1 comment

1 answer

✓ Accepted answer

Try this:

Let me know if any error pops up, because I'm a bit rusty on animations, and I can't test to see if it works due to ROBLOX not allowing external animations to work in Studio.

local player = game.Players.LocalPlayer 
local anim = Instance.new("Animation")  -- iirc, you don't pass the parent parameter
anim.AnimationId = "http://www.roblox.com/asset/?id=483517771" -- animationId's need to be in this format to find the ID of the animation. But they can also be in the format "rbxassetid://483517771" to work

local UIS = game:GetService('UserInputService')

local newAnimation = nil -- just using the regular variable, rather than a local one

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		newAnimation = player.Character.Humanoid:LoadAnimation(anim)
		newAnimation:Play()
	end
end)

If it worked, feel free to accept this answer. It helps the both of us!!

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