Change dummy animation with a script

Hello, I need help with a script, I am trying when someone says something in chat the dummy plays an animation
but i can’t script

local TeleportService = game:GetService("TeleportService")
	
game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "test" then
			game.Workspace.Sound.Playing = false
			script.Sound:Play()
			wait(12)
			TeleportService:Teleport(10447589013, player)
		end
	end)
end)

image

the script is the dummy are separated

1 Like
local TeleportService = game:GetService("TeleportService")
local dummy = game.Workspace.Dummy
local humDummy = dummy:WaitForChild("Humanoid")
local anim = dummy.Script.Chillidle
local loadedAnim = humDummy:LoadAnimation(anim)

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "test" then
			game.Workspace.Sound.Playing = false
			script.Sound:Play()
           loadedAnim:Play()
			wait(12)
			TeleportService:Teleport(10447589013, player)
		end
	end)
end)

This should work

1 Like

Update, thanks you script works but i wasn’t really clear
The animation start playing but i already have another looped animation
image
so it just reset, sorry
The chillidle is the first animation and i want it to be replace or disabled for play the other one

1 Like

image
i tried that but i don’t know how it works

1 Like
local TeleportService = game:GetService("TeleportService")
local dummy = game.Workspace.Dummy
local humDummy = dummy:WaitForChild("Humanoid")
local anim = dummy.Script.Animation
local loadedAnim = humDummy:LoadAnimation(anim)

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "test" then
          for i,v in pairs(humDummy:GetPlayingAnimationTracks()) do
	              v:Stop()
          end
			game.Workspace.Sound.Playing = false
			script.Sound:Play()
           loadedAnim:Play()
			wait(12)
			TeleportService:Teleport(10447589013, player)
		end
	end)
end)

Alright this should work, GetPlayingAnimationTracks gets all playing animations in a table, then we run a loop to stop all the animations in the list.

Thanks you for your help
it works perfectly

1 Like

Why not just declare an upvalue for each animation track?

1 Like