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

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

Asked by 7 years ago

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)
0
That is not a valid animation id. Programical 653 — 7y

3 answers

Log in to vote
0
Answered by 7 years ago

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

Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago
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.

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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" 

Answer this question