Studio中LoadAnimation不正常工作

我正在制作一个R6动画游戏,并试图加载动画。但是,我的代码中有一个错误。请看下面的注释行:

-- script
local Animations = {"happy rbxassetid://5067384181"}
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Wait()
    require(workspace.Anim):Init(Animations,player.Character:WaitForChild("Humanoid"))
end)

-- module
local module = {}
local animations={}
local anim
local Play={}
local n,ky
function module:Init(anims,hum)
    for _,anId in pairs(anims) do
        ky=string.split(anId," ")[1]
        anId=string.split(anId," ")[2]
        anim=Instance.new("Animation")
        anim.AnimationId=anId
        animations[ky]=anim
    end
    for k,an in pairs(animations) do
        Play[k]=hum:LoadAnimation(an) -- error here: (player.Character) must be a descendant of the game object
    end
    game.Players:GetPlayerFromCharacter(hum.Parent).Chatted:Connect(function(m)
        if string.sub(m,1,4)=="/em " then
            n=string.sub(m,5)
            if not Play[n] then return end
            for _,an in pairs(hum:GetPlayingAnimationTracks()) do
                an:Stop()
            end
            Play[n]:Play()
        else return end
    end)
end
return module

编辑:以下是修正后的代码:

-- script
local Animations = {"happy rbxassetid://5067384181"}
game.Players.PlayerAdded:Connect(function(player)
    local char=player.Character or player.CharacterAdded:Wait()
    repeat wait(0.01) until char.Parent~=nil
    require(workspace.Anim):Init(Animations,player.Character:WaitForChild("Humanoid"))
end)

编辑(再次):在较长的动画(3秒)中,每次动画都会在一半处停止并重置,我无法解决它。有没有什么办法解决这个问题?

点赞