Hi, i’m trying to get an animation to play on a player as soon as they join, alongside some audio, i’d appreciate if someone could help me figure out how to make this work. I was trying to achieve the dance to start playing and the audio play with it too, but all that happens is an error comes up saying
[22:59:49.850 - LoadAnimation requires the Humanoid object (dameii.Humanoid) to be a descendant of the game object]
22:59:49.851 - Stack Begin
[22:59:49.854 - Script ‘Workspace.Script’, Line 13]
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
local gu = humanoid.Parent:FindFirstChild("Animate")
gu:Remove()
local eyeyye = script.dance
eyeyye.Parent = humanoid.Parent
while true do
local thesong = eyeyye.Audio
thesong:Play()
local animation1 = thesong.Parent.thedance
animation1.Parent = humanoid.Parent
local w = humanoid:LoadAnimation(animation1)
w:Play()
wait(35.865999999999999659)
end
end)
end)
Any help would be appreciated, thank you so much :D
Animations should be handled on the client because the client has network ownership of their character. This error happens because the humanoid isn’t parented to the workspace yet. You should use the code below in a local script, and I added an if statement that checks if the character’s parent is nil, if so, the script will wait until it has its parent changed:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local eyeyye = script.dance
eyeyye.Parent = humanoid.Parent
local thesong = eyeyye.Audio
thesong:Play()
local animation1 = thesong.Parent.thedance
animation1.Parent = humanoid.Parent
if not (char.Parent) then
char.AncestrChanged:Wait()
end
local w = humanoid:LoadAnimation(animation1)
w:Play()
thank you so much, I tried this script and tweaked it around as it was showing errors at first. Now it states
[23:30:38.810 - Players.dameii.PlayerScripts.dance:13: attempt to index nil with ‘Parent’]
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animation1 = script.thedance
animation1.Parent = humanoid.Parent
local thesong = script.Audio
thesong.Parent = humanoid.Parent.Head
thesong:Play()
if not (char.Parent) then
char.AncestrChanged:Wait()
end
local w = humanoid:LoadAnimation(animation1)
w:Play()
if you could help with this, that would be appreciated also, thanks again!