Hello developers!
This topic is very important to both my game and I, so I will keep it as short as possible in the hopes that more people will spend the time to read this topic. If I am missing any information, please do not hesitate to let me know in the replies.
I am developing a game in which players “walk the runway” and strike a pose when they get to the center of said runway. The animation that is loaded and played on the character (a cloned character) is the specific animation that the player has equipped. It’s cloned and loaded to the humanoid, and then played.
Thing is, it doesn’t load. And then it doesn’t play. At least that is what I think is happening.
Here's the code that handles the runway (cleaned of excess):
local EquippedFolder = Player:WaitForChild("Equipped")
Status.Value = "Now on the runway: " .. Player.Name
local Character = Player.Character or Player.CharacterAdded:Wait()
Character.Archivable = true
local Rig = Character:Clone()
Rig.Name = "RIG"
local Humanoid = Rig:WaitForChild("Humanoid")
if Rig:FindFirstChild("Animate") then
Rig.Animate:Destroy()
end
local AnimateScript = script.Animate:Clone()
for _, AnimationValue in pairs(Rig:WaitForChild("Animate"):GetChildren()) do
AnimationValue.Parent = AnimateScript
end
AnimateScript.Parent = Rig
AnimateScript.Disabled = false
local Waypoints = {
RunwayFolder.WaypointParts.BackLeft.Position,
RunwayFolder.WaypointParts.FrontLeft.Position,
RunwayFolder.WaypointParts.Front.Position,
RunwayFolder.WaypointParts.FrontRight.Position,
RunwayFolder.WaypointParts.BackRight.Position,
RunwayFolder.WaypointParts.Exit.Position,
}
Rig.Parent = workspace.FocusedRig
Rig:SetPrimaryPartCFrame(RunwayFolder.WaypointParts.Enter.CFrame)
local ChosenAnimation = ItemsFolder.Emotes:WaitForChild(EquippedFolder:WaitForChild("EquippedEmote").Value):Clone()
local LoadedAnimation = Humanoid:LoadAnimation(ChosenAnimation)
LoadedAnimation.Looped = false
wait(2)
for v, Position in pairs(Waypoints) do
Humanoid:MoveTo(Position)
Humanoid.MoveToFinished:Wait()
if v == 3 then
local LoadedAnimation = Rig.Humanoid:LoadAnimation(ChosenAnimation)
LoadedAnimation.Looped = true
if LoadedAnimation.Length == 0 then repeat wait() until LoadedAnimation.Length ~= 0 end
local AnimationLength = LoadedAnimation.Length
local WaitTime = 0
if AnimationLength > 8 then
WaitTime = 6
elseif AnimationLength < 4 then
repeat if not ((WaitTime + AnimationLength) > 5) then WaitTime += AnimationLength else break end until WaitTime <= 6
LoadedAnimation.Looped = false
else
WaitTime = AnimationLength
end
LoadedAnimation:Play()
repeat wait() until LoadedAnimation.IsPlaying
wait(WaitTime)
LoadedAnimation:Stop()
ParticleExplosion(Rig,ItemsFolder.Particles:WaitForChild(EquippedFolder:WaitForChild("EquippedParticle").Value):GetChildren(),false)
end
end
Rig:Destroy()
Initially, I tried loading it once before the playing the animation. Didn’t work. Then I tried loading it before the player starts walking and then playing it when they reach the middle of the runway. Also didn’t work. My current solution is loading it before the runway, and then playing it when they reach the middle, although this also isn’t working very well for me.
I am preloading all the animations using PreloadAsync, and these work fine when played with rigs in viewports etc. I have no idea what the issue is!
Looping the animation isn’t working either. In the code you can see that I am setting looped to true straight after the animation is loaded, but the animations - if they happen to be played - do not loop 100% of the time.
I would greatly appreciate any feedback for this, and any solutions that anyone may come across. I am aware that LoadAnimation is depreciated but I never was able to work out what the new system that I should use instead was (it was not on devleoper.roblox.com) so I never made the switch.
Thank you!