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

How do i fix my character animation script?

Asked by 9 years ago

Hi, i recently made a script but it's not playing the animation on my character.

local Player = game.Players.LocalPlayer;
local AnimId = (248335946);

local URL = ("http://www.roblox.com/asset/?id=248335946");
local Anim = (URL..tostring(AnimId));
Player.CharacterAdded:connect(function(Char)
 local Hum = Char:WaitForChild("Humanoid");
 local Track = Hum:LoadAnimation(Anim)
 Track:Play();
 return nil;
end);

1 answer

Log in to vote
0
Answered by 9 years ago

Simple fix, you're concatanating the URL string that already has an asset Id with another asset Id, creating an invalid animation asset. Another thing is, while loading animations this way, we actually need the physical animation object to load. So we can just create with with Instance.new:

local Player = game.Players.LocalPlayer;
-- Got rid of the AnimId entirely
local Anim = "http://www.roblox.com/asset/?id=248335946" -- Already valid

Player.CharacterAdded:connect(function(Char)
    local Hum = Char:WaitForChild("Humanoid")
    local AnimObj = Instance.new("Animation",Hum)
    AnimObj.AnimationId = Anim
    local Track = Hum:LoadAnimation(AnimObj )
    Track:Play()
    AnimObj:Destroy()
    -- We also don't need that return value
end)

Or ...

local Player = game.Players.LocalPlayer
local AnimId = 248335946

local URL = "http://www.roblox.com/asset/?id=" -- Got rid of the Id here
local Anim = URL..tostring(AnimId)
Player.CharacterAdded:connect(function(Char)
    local Hum = Char:WaitForChild("Humanoid")
    local AnimObj = Instance.new("Animation",Hum)
    AnimObj.AnimationId = Anim
    local Track = Hum:LoadAnimation(AnimObj)
    Track:Play()
    AnimObj:Destroy()
end)
0
Still dosen't work. :( elatedkakashi123 0 — 9y
0
Oops, I forgot loading animations requires using the Animation object. I'll revise my answer. ScriptGuider 5640 — 9y
0
Concatenation can be done without tostring (as the compiler converts automatically), and it can also be done directly. But, your choice, i guess. Marios2 360 — 9y
0
With numbers, yes. But the concatenation process can only be preformed on the number as a variable, not a direct value. However, the same rules don't apply for other arbitrary values. ScriptGuider 5640 — 9y
Ad

Answer this question