Change player animations during runtime

I’m working on a game in which players’ rigs are swapped out when they enter a round. The original player.Character is deleted, and replaced with a new rig cloned from ServerStorage. However, this rig does not animate. I’ve tried taking a player Animate script and replacing the animation IDs with custom ones design for the new rig (it’s not R6), however this Animate script does not seem to play animations after the player loads into the round. Testing the same animations & rig as a StarterCharacter worked fine, but when loading the rig onto the player in code, the Animate script doesn’t seem to function. I can’t use a StarterCharacter because each player may have a different class / skin for their character. If anyone knows why the Animate script doesn’t function when cloned onto the player character, I can script a solution myself. Attached is the code that loads the character and Animate script, if needed. Thank you in advance! :smiley:

local function applyRigToPlayer(player, rig)
	player.Character:Destroy()
	local clonedRig = rig:Clone()
	clonedRig.Parent = workspace
	clonedRig.Name = player.Name
	
	local animate = serverStorage.Animations.Script.Animate:Clone()
	animate.Parent = clonedRig
	
	player.Character = clonedRig
	
	replicatedStorage.Events.ResetCamera:FireClient(player)
end

Set clonedRig’s parent to workspace after you parent the Animate script and change the player’s Character property to the rig:

local function applyRigToPlayer(player, rig)
	player.Character:Destroy()
	local clonedRig = rig:Clone()
	clonedRig.Name = player.Name
	
	local animate = serverStorage.Animations.Script.Animate:Clone()
	animate.Parent = clonedRig
	
	player.Character = clonedRig
    clonedRig.Parent = workspace -- after character property has been set and animate script has been parented to clonedRig
	
	--replicatedStorage.Events.ResetCamera:FireClient(player) -- you don't need this
end
1 Like

Thank you! Marked this as the solution — it worked like a charm. Been sweating over this for a day or so, surprised to see it was such a simple fix. T-T

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.