I’m trying to write a function that makes all players of a particular team dance, but I cant seem to get it to work. Here my code so far:
local animation = game.workspace.R6Dance
function allplayersdance()
for _, player in pairs(game.Teams.Playing:GetPlayers()) do
local humanoid = player:WaitForChild("Humanoid")
local dance = humanoid:LoadAnimation(animation)
dance:Play()
wait(5)
dance:Stop()
end
end
Has anyone been able to make this work? Thanks in advance!
function allplayersdance()
for _, player in pairs(game.Teams.Playing:GetPlayers()) do
local humanoid = player:FindFirstChild("Humanoid")
local dance = humanoid:LoadAnimation(animation)
if (humanoid) then
dance:Play()
wait(10)
dance:Stop()
else
print("No humanoid! Error!")
end
end
end
You’re still using the Player object to reference the humanoid. Do what @DosenSuppe2_0 said:
function allplayersdance()
for _, player in pairs(game.Teams.Playing:GetPlayers()) do
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
local dance = humanoid:LoadAnimation(animation)
dance:Play()
wait(10)
dance:Stop()
else
print("No humanoid! Error!")
end
end
end
Thank you for your help! The players are now dancing!
One slight issue, only one of them dances, then after 10 seconds the next one dances. I’m trying to make them all dance simultaneously for 10 seconds. I’ve tried changing the script to this:
function allplayersdance()
for _, player in pairs(game.Teams.Playing:GetPlayers()) do
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
local dance = humanoid:LoadAnimation(animation)
dance:Play()
else
print("No humanoid! Error!")
end
end
wait(10)
dance:Stop()
end
But to no avail. I’ve even tried creating a whole other function called allplayersstopdancing() but again, can’t get it to work. Do you have any idea on how I could achieve this?
function allplayersdance()
for _, player in pairs(game.Teams.Playing:GetPlayers()) do
task.spawn(function()
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
local dance = humanoid:LoadAnimation(animation)
dance:Play()
else
print("No humanoid! Error!")
end
task.wait(10)
dance:Stop()
end)
end
end
Sidenote: The dance is meant to be the R6 /e dance2 animation, but for some reason the arms don’t fully rise like they’re meant to? Like they sit at a 45 degree angle as opposed to the 90 degree T-pose they’re meant to. Is that just a bug or am I doing something wrong?
function allplayersdance()
for _, player in pairs(game.Teams.Playing:GetPlayers()) do
task.spawn(function()
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
local track = humanoid:LoadAnimation(animation)
track:Play()
task.wait(10)
track:Stop()
else
print("No humanoid! Error!")
end
end)
end
end
It works perfectly! Thank you
I will mark you answer as the solution.
Do you have any idea why the characters arms aren’t fully up like they’re supposed to?
If you don’t, I might make another post asking the devforum.
Thank you for your help regardless!
Try changing the track priority. Change the code to this and tell me if it works:
function allplayersdance()
for _, player in pairs(game.Teams.Playing:GetPlayers()) do
task.spawn(function()
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
local track = humanoid:LoadAnimation(animation)
track.Priority = Enum.AnimationPriority.Action
track:Play()
task.wait(10)
track:Stop()
else
print("No humanoid! Error!")
end
end)
end
end