Hey, I’m trying to make every single player dance at the same time. I copied someone else’s script, but it doesn’t work as I want it to since it was made in a local script. I changed some stuff in it without luck. Any help is appreciated! Right now I’m getting the error: “attempt to index nil with 'WaitForChild” when running the script.
local emote = Animation -- replace emote with the name of the emote
local btn = script.Parent
local plr = game.Players:GetChildren()
local char = plr.Character
local hum = char:WaitForChild("Humanoid",10)
local CanEmote = true
local CoolDown = 1
if CanEmote == true then
CanEmote = false
local dance = hum:LoadAnimation(script:FindFirstChild(emote))
dance:Play()
wait(CoolDown + dance.Length)
CanEmote = true
end
2 Likes
game.Players:GetChildren()
is a list, not an Instance. To get all player instances, you need to do a pairs loop.
for i, v in pairs(game.Players:GetChildren()) do
-- code
end
it doesn’t work as I want it to since it was made in a local script
This is something normal because animations can be played only by local scripts (alternatively I’m dumb but I’ve never found someone playing animations on a server script)
Make a local script with the animation, on a server script use RemoteEvent
and FireAllClients()
to play the animation on everyone.
Will players then be able to see others dance aswell?
Yes, even if played by a local script. Local scripts aren’t 100% local.
An explanation of animation replication is here: Animation
I made this script but now I get the error: “Argument 1 missing or nil”. (This is on the line where it says ‘local dance’) @Spiderr12PL
game.ReplicatedStorage.triplebruh.OnClientEvent:Connect(function()
for i, v in pairs(game.Players:GetChildren()) do
local emote = cool
local plr = v
local char = plr.Character
local hum = char:WaitForChild("Humanoid",10)
local CanEmote = true
if CanEmote == true then
CanEmote = false
local dance = hum:LoadAnimation(script:FindFirstChild(emote))
dance:Play()
wait(dance.Length)
CanEmote = true
end
end
end)
Change it to: script:WaitForChild(emote)
Also playing the animation on only LocalPlayer’s character in one local script per client should be enough because server will fire the event to each client.
Alright so I changed the script a lil bit, and now I managed to get no errors at all. But my player won’t play the animation and I don’t know why. I read somewhere I have to put the animation priority up, but I don’t know where I am supposed to do that.
game.ReplicatedStorage.triplebruh.OnClientEvent:Connect(function()
local emote = script.cool
local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid",10)
local CanEmote = true
if CanEmote == true then
CanEmote = false
local dance = hum:LoadAnimation(emote)
dance:Play()
wait(dance.Length)
CanEmote = true
end
end)
How do I load the animation into the plugin? I’m trying to get the players to floss. This is the animation: Floss Dance - Roblox
It’s not an animation, but an asset. It is possible to get the animation from it. I pasted it to the Roblox Studio command bar to get the animation ID:
local id = '3823158750'; local is = game:GetService('InsertService'); print(is:LoadAsset(5917570207):FindFirstChildOfClass'Animation'.AnimationId)
Animartion ID: 5917459365
3 Likes