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

How do I play the animation with KeyDown?

I am trying to make it so when I press "e" on the keyboard, it plays an animation. I feel like the code should be right, but it says in the studio output: "Animation "https://www.roblox.com//asset/?id=https://www.roblox.com/library/963441784/Watch-Check-Animation&serverplaceid=0" failed to load in "Animation.AnimationId": Animation failed to load"

local mouse = game.Players.LocalPlayer:GetMouse()
local char = game.Players.LocalPlayer.Character
enabled = false

function KeyD(key)
	if enabled then
		enabled = false
		key = key:lower()
		if key == "e" then
			local emote = Instance.new("Animation")
			emote.AnimationId = "https://www.roblox.com/library/963441784/Watch-Check-Animation"
			local animloader = char.Humanoid:LoadAnimation(emote)
			animloader:Play()
		end
		enabled = true
	end
end

Thanks for the help. I guess.

1 answer

KeyDown is a depricated function a.k.a it can't be used anymore it only works in studio.

it is replaced for ther UserInputService

Do this:

plr = game.Players.LocalPlayer
chr = plr.Character

game:GetService('UserInputService').InputBegan:Connect(function(input, process)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.E and plr and chr then
			-- ur animation stuff
		end
	end
end)

also uhh try to make ur animation a child of the script like this (bcuz it may just be having no parent but the game itself)

local emote = Instance.new('Animation', script)

and also uhhhhhh say the AnimationId is this: "rbxassetid://(ur Idnumber)"

2 comments

0

What scripters usually do is local uis = game:GetService("UserInputService") then do uis.InputBegan:Connect(function(input,process) end) instead of making a fat line of code

0

Every scripter is different. Also, why make a variable if youre only going to use it once?

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