Animation not working for other players

I have a script to repeatedly play the animation of a player when they join the game, although this script seems to be working only for me and not for other players.
Would anyone have an idea of how to fix this?

Here is the script:

-- Get player
local player = game:GetService("Players").LocalPlayer

-- Wait for animation
local animation = script:WaitForChild("Animation")

-- Make this variable local
local animDribbleRTrack = nil

-- Make a function that takes a character and loads an animation on it
-- Then sets the animDribbleRTrack variable to be that animation
local function onCharacterAdded(character)
	local humanoid = character:WaitForChild("Humanoid")
	local animator = humanoid:WaitForChild("Animator")

	animDribbleRTrack = animator:LoadAnimation(animation)
end

-- If there is already a character, then load the animation on it
if player.Character then
	onCharacterAdded(player.Character)
end
-- When the player gets a new character, load the animation on it
player.CharacterAdded:Connect(onCharacterAdded)

-- Every 5 seconds, if there is an animation, play it
while true do
	task.wait(5)
	if animDribbleRTrack then
		animDribbleRTrack:Play()
	end
end

image

1 Like