How to play animation when type command

I want to be able to type a command in chat and play an animation continuously just like /dance and /point I want to do that exactly but add more animation

I dont know how to script so I looked on youtube and found a video and used this script in workspace

I just want to be able to say .defaultdance and have a default dance animation play which i already have thanks
(i dont use dev formum that much)

4 Likes

Try use

local DanceAnimation = script:WaitForChild("DanceAnimation") -- make animation object inside script and past animation id in
local Character = player.Character
local AnimationTrack = Character:WaitForChild("Humanoid"):LoadAnimation(DanceAnimation)
AnimationTrack:Play()

This should work

I think im doing something wrong
image

I did put the animation object in it and put the id in

You forgot delete end there I believe.

I dont know i think im stupid
image
image

Ooh, you forgot to add player variable before playing animation, just before playing animation add line:

 local player = Players:FindFirstChild(name)

when i move how do i make it stop because i want it to be excatly like the /e dance command whne i move it stop how do i do that?

Try add next lines in if statement when you playing animation:

 local Humanoid = player.Character:WaitForChild("Humanoid")
 Humanoid.Running:Connect(function(Speed)
      if Speed > 0 then
          if AnimationTrack ~= nil then
              AnimationTrack:Stop()
          end
      end
 end)

Or you just can stop player from moving until animation stops playing, but this should work.

local Players = game:GetService(“Players”)

local command1 = “.dd1”
local command2 = “!lasergun”

function onChatted(chat, recipient, speaker)

local name = speaker.Name
chat = string.lower(chat)

if (chat == command1) then

local player = Players:FindFirstChild(name)
local DanceAnimation = script:WaitForChild(“DanceAnimation”) – make animation object inside script and past animation id in
local Character = player.Character
local AnimationTrack = Character:WaitForChild(“Humanoid”):LoadAnimation(DanceAnimation)
AnimationTrack:Play()
local Humanoid = player.Character:WaitForChild(“Humanoid”)
Humanoid.Running:Connect(function(Speed)
if Speed > 0 then
if AnimationTrack ~= nil then
AnimationTrack:Stop()
end
end
end)
end

if (chat == command2) then
	
	local player = Players:FindFirstChild(name)
	
	game.ServerStorage.Gun:clone().Parent = player:WaitForChild("Backpack")
end

end

function onPlayerEntered(Player)
Player.Chatted:connect(function(chat, recipient) onChatted(chat, recipient, Player) end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

that is what i did now it doesnt play the animation
i just gave it to you becasue i honestly dont know what im doing

1 Like

Do you have any output errors?

wait wat it started working what is this garbage thanks alot dude <3

2 Likes

Ooh lol, no problem :slight_smile: