I’m interested in playing multiple different animations based on what status the player is currently in. If the player needs to get revived, they’re going to have a crawling animation in place for the walking animation. The status can change many times in one life and I’m unsure how to change the animations.
I’ve tried changing the id of the animations inside of Roblox’s animate script but that has weird problems: sometimes it doesn’t replicate to other clients and other times it just doesn’t run. I tried cloning the animate script with the new animation ids and destroying the old one, but this feels hacky and the old animations are still running and override the new ones.
Note: when I changed the animation ids, I did it on the server.
The animations don’t replicate. The script is the same one on the wiki but I also load the character and apply a description before. The idle animation works fine but the walk/run animations don’t play and they’re not content deleted. The script and a video can be found below
plr:LoadCharacter()
plr.Character.Humanoid:ApplyDescription(script.Human)
Batteries:Add(plr, map.BatterySpawns)
Alive:Add("Human", plr)
GAME_REMOTE:FireClient(plr, "Human")
Shortcuts:WeldFlashlight(plr.Character)
for _, playingTracks in pairs(plr.Character.Humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
plr.Character.Animate.idle.Animation1.AnimationId = "http://www.roblox.com/asset/?id=4875521976"
plr.Character.Animate.idle.Animation2.AnimationId = "http://www.roblox.com/asset/?id=4875521976"
plr.Character.Animate.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id=4875343908"
plr.Character.Animate.run.RunAnim.AnimationId = "http://www.roblox.com/asset/?id=4875343908"
I justed tested it with 3 animations and it didn’t replicate any of them. The script is pretty unorganized because I just used it for testing. The script changes the default walk/run animation. After 10 seconds, the animations changes again and that happens a third time. Am I missing something?
local chr = script.Parent
if chr.Name == "Player1" then
for _, playingTracks in pairs(chr.Humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
chr.Animate.idle.Animation1.AnimationId = "http://www.roblox.com/asset/?id=4875521976"
chr.Animate.idle.Animation2.AnimationId = "http://www.roblox.com/asset/?id=4875521976"
chr.Animate.walk.WalkAnim.AnimationId = "rbxassetid://4792448183"
chr.Animate.run.RunAnim.AnimationId = "rbxassetid://4792448183"
wait(10)
for _, playingTracks in pairs(chr.Humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
chr.Animate.idle.Animation1.AnimationId = "rbxassetid://4863840711"
chr.Animate.idle.Animation2.AnimationId = "rbxassetid://4863840711"
chr.Animate.walk.WalkAnim.AnimationId = "rbxassetid://4864108551"
chr.Animate.run.RunAnim.AnimationId = "rbxassetid://4864108551"
wait(10)
for _, playingTracks in pairs(chr.Humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
chr.Animate.idle.Animation1.AnimationId = "http://www.roblox.com/asset/?id=4875521976"
chr.Animate.idle.Animation2.AnimationId = "http://www.roblox.com/asset/?id=4875521976"
chr.Animate.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id=4875343908"
chr.Animate.run.RunAnim.AnimationId = "http://www.roblox.com/asset/?id=4875343908"
end
try putting the script in the ServerScriptService and doing this instead
local function onCharacterAdded(char)
local humanoid = char:WaitForChild("Humanoid")
for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
playingTracks:Stop(0)
end
local animateScript = char:WaitForChild("Animate")
-- change the Id's here
end
local function onPlayerAdded(plr)
plr.CharacterAppearanceLoaded:Connect(onCharacterAdded)
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
it’s basically the script the roblox developer hub used
From my experience, replacing the animation ids in the default animate script will run into issues , your going to have to make a custom script , and drop into characterscripts. your then going to have to define and load the animations yourself and have them play during set conditions, they are going to override the default animations if you do it this way.
For crawling just check the Humanoid.Running function and if the player is moving, and the “Downed” variable is active then an animation can be played until the players speed goes back to 0.
If you need a more in depth explanation feel free to contact me on discord @Drac#5808
I’ve created my own script and I’m having the same issues. It works fine the first time around, but when it changes it stop replicating. Same thing as Roblox’s own script.
--Services
local RunService = game:GetService("RunService")
--Constants
local CHR = script.Parent
local HUM = CHR:WaitForChild("Humanoid")
local STATE = Enum.HumanoidStateType
--Variables
local loadedAnimations = {}
local curAnim
--Functions
local function playAnimation(anim)
local animObject = script.Animations:FindFirstChild(anim)
local animId = animObject and string.match(animObject.AnimationId, "%d+")
if not animId then error("Animation object not found") end
if curAnim and curAnim == loadedAnimations[anim..animId] then return end
local loadedAnim = loadedAnimations[anim..animId]
if curAnim then
curAnim:Stop()
end
if loadedAnim then
loadedAnim:Play()
else
loadedAnimations[anim..animId] = HUM:LoadAnimation(animObject)
loadedAnimations[anim..animId]:Play()
end
curAnim = loadedAnimations[anim..animId]
end
--Events
local runConnection
HUM.StateChanged:Connect(function(old, new)
if new == STATE.Running or new == STATE.RunningNoPhysics then
if not runConnection then
runConnection = RunService.Heartbeat:Connect(function()
print(#HUM:GetPlayingAnimationTracks())
print(curAnim)
if HUM.MoveDirection == Vector3.new(0, 0, 0) then
playAnimation("Idle")
else
playAnimation("Walk")
end
end)
end
else
if runConnection then
runConnection:Disconnect()
runConnection = nil
end
end
end)
I fixed this problem by creating a new animation instance. With Roblox’s and my method, we were both overriding the animationid and that is what’s causing the problem.