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

what is the problem with this code currently i keep getting error?

So im trying to make the player punch by pressing z but i keep getting this error

Animation "http://www.roblox.com/asset/?id=http://www.roblox.com/asset765720015&serverplaceid=0" failed to load in "Animation.AnimationId": Animation failed to load

so I'm unsure what i can do to fix it i've tried using other peoples animation on key codes but they don't seem to work either.

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()

local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset765720015" -- id of animation

mouse.KeyDown:connect(function(key)
	if key == "z" then 
		local playAnim = humanoid:LoadAnimation(anim)
		playAnim:Play()
	end
end)

1 comment

0

That is not a valid animation id.

3 answers

The problem is that the animation failed to load.

Here's a solve, use WaitForChild

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character:WaitForChild("Humanoid") -- Waits For Humanoid
local mouse = player:GetMouse()
 
local anim = Instance.new("Animation")
anim:WaitForChild("AnimationId") = "http://www.roblox.com/asset765720015" -- id of animation
 
mouse.KeyDown:connect(function(key)
    if key == "z" then
        local playAnim = humanoid:LoadAnimation(anim)
        playAnim:Play()
    end
end)

This should stop the errors and load the animation.

If stopped error then Upvote and accept answer plz :D

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()

local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/765720015" -- id of animation

mouse.KeyDown:connect(function(key)
    if key == "z" then 
        local playAnim = humanoid:LoadAnimation(anim)
        playAnim:Play()
    end
end)

I think it will work now. You forgot to put / on asset765720015 to seperate the word asset from id.

Explanation

On line 7, you wrote,

anim:WaitForChild("AnimationId") = "http://www.roblox.com/asset765720015" 

http://www.roblox.com/asset765720015 will throw error 404 because it is not a valid url or whatever.

To get a roblox asset in programming, you can do:

rbxassetid://765720015

Solution

So you should replace line 7 with:

anim:WaitForChild("AnimationId") = "rbxassetid://765720015" 

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