New Character Doesn't Have Animations

Hello,
I am currently testing with switching the character of a player. I have got setting the new character and camera correct but ran into a problem. When I switch the player’s character, the new character I switched the player to doesn’t have any animations. This means it does not play the idle, walk, jump, and all other default animations a character would usually have. The character already has the local animate script inside of it that all other characters have, yet still no animations play.

Note: The new character I give to the player is parented to the workspace.

Server Script

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local guy = workspace.Ice
	game.ReplicatedStorage.Cam:FireClient(player, guy)
	player.Character = guy
end)

Local Script

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

game.ReplicatedStorage.Cam.OnClientEvent:Connect(function(guy)
	camera.CameraSubject = guy.Humanoid
end)

Other Character’s Stuff

1 Like

Can I see the animation script?

1 Like

It’s just the default animation script that goes into every character. Go into studio, play it, then look inside your character for it.

1 Like

Are you saying you want a character to look a certain way but it is not being animated?

Partially, I am switching the player’s character to another character model, no different from a regular Roblox character. The camera goes to it and I can move as the new character model but walking, jumping, and all other animations do not play.

So first, delete your current Animate Script and add this one.

AnimateScript.rbxm (7.1 KB)

2 Likes

This does make it where the new character now plays all the animations but they are quite noticeably delayed. Anyway to make it not delayed?

I found it being delayed because it is a server script and not a local one. So now I need to know how to make it where the local script works. I am guessing I would have to place it somewhere else, but don’t know where that would be.

Copy the code in it and put that code in a localscript (make sure to name it Animate) and put the items in that script too.

I did and it doesn’t work, I also placed a print function at the beginning and that print didn’t print into the output which means the whole script together just doesn’t run. I think I need to place it in another spot but I don’t know where to place it.

Hmmm alright wait let me do something.

Alright I fixed it. Usually you would put it in StarterCharacterScripts but when switching players it was not respawning the character so that doesn’t work. So I disabled the local script and put it in ServerScriptService. When a player goes to another character I clone the local script, insert it into the new character, and then enable the script. Also thanks for your help.

2 Likes

For anyone reading this post 4 years later like me (or more), here’s another way to fix it cuz I didn’t understood @Icey_CD 's version bc I’m lowkey too dumb

you can re adapt the default “Animate” localscript to put not into the character, but into the player by putting it into StarterPlayerScripts and re adapting the script (I did it easly with deepseek and a few fixes)

image

to clear up the default animate script you need to create an empty local script called animate in the starter character scripts (like in the picture)

And here is the new code handling new characters for the localscript in StarterPlayerScripts (don’t forget to past into it all of the stuff there was in the default animate local script) :

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Figure = nil
local Humanoid = nil
local pose = "Standing"

local EMOTE_TRANSITION_TIME = 0.1

local userAnimateScaleRunSuccess, userAnimateScaleRunValue = pcall(function() return UserSettings():IsUserFeatureEnabled("UserAnimateScaleRun") end)
local userAnimateScaleRun = userAnimateScaleRunSuccess and userAnimateScaleRunValue

local function getRigScale()
	if userAnimateScaleRun then
		return Figure:GetScale()
	else
		return 1
	end
end

local currentAnim = ""
local currentAnimInstance = nil
local currentAnimTrack = nil
local currentAnimKeyframeHandler = nil
local currentAnimSpeed = 1.0
local animTable = {}
local animNames = { 
	idle = 	{	
		{ id = "http://www.roblox.com/asset/?id=180435571", weight = 9 },
		{ id = "http://www.roblox.com/asset/?id=180435792", weight = 1 }
	},
	walk = 	{ 	
		{ id = "http://www.roblox.com/asset/?id=180426354", weight = 10 } 
	}, 
	run = 	{
		{ id = "run.xml", weight = 10 } 
	}, 
	jump = 	{
		{ id = "http://www.roblox.com/asset/?id=125750702", weight = 10 } 
	}, 
	fall = 	{
		{ id = "http://www.roblox.com/asset/?id=180436148", weight = 10 } 
	}, 
	climb = {
		{ id = "http://www.roblox.com/asset/?id=180436334", weight = 10 } 
	}, 
	sit = 	{
		{ id = "http://www.roblox.com/asset/?id=178130996", weight = 10 } 
	},	
	toolnone = {
		{ id = "http://www.roblox.com/asset/?id=182393478", weight = 10 } 
	},
	toolslash = {
		{ id = "http://www.roblox.com/asset/?id=129967390", weight = 10 } 
	},
	toollunge = {
		{ id = "http://www.roblox.com/asset/?id=129967478", weight = 10 } 
	},
	wave = {
		{ id = "http://www.roblox.com/asset/?id=128777973", weight = 10 } 
	},
	point = {
		{ id = "http://www.roblox.com/asset/?id=128853357", weight = 10 } 
	},
	dance1 = {
		{ id = "http://www.roblox.com/asset/?id=182435998", weight = 10 }, 
		{ id = "http://www.roblox.com/asset/?id=182491037", weight = 10 }, 
		{ id = "http://www.roblox.com/asset/?id=182491065", weight = 10 } 
	},
	dance2 = {
		{ id = "http://www.roblox.com/asset/?id=182436842", weight = 10 }, 
		{ id = "http://www.roblox.com/asset/?id=182491248", weight = 10 }, 
		{ id = "http://www.roblox.com/asset/?id=182491277", weight = 10 } 
	},
	dance3 = {
		{ id = "http://www.roblox.com/asset/?id=182436935", weight = 10 }, 
		{ id = "http://www.roblox.com/asset/?id=182491368", weight = 10 }, 
		{ id = "http://www.roblox.com/asset/?id=182491423", weight = 10 } 
	},
	laugh = {
		{ id = "http://www.roblox.com/asset/?id=129423131", weight = 10 } 
	},
	cheer = {
		{ id = "http://www.roblox.com/asset/?id=129423030", weight = 10 } 
	},
}
local dances = {"dance1", "dance2", "dance3"}

local emoteNames = { wave = false, point = false, dance1 = true, dance2 = true, dance3 = true, laugh = false, cheer = false}

local jumpAnimTime = 0
local jumpAnimDuration = 0.3
local fallTransitionTime = 0.3

local stopAllAnimations, setAnimationSpeed, keyFrameReachedFunc, playAnimation, onRunning, onDied, onJumping, onClimbing, onGettingUp, onFreeFall, onFallingDown, onSeated, onPlatformStanding, onSwimming, configureAnimationSet, scriptChildModified, initializeCharacter

stopAllAnimations = function()
	local oldAnim = currentAnim
	if emoteNames[oldAnim] ~= nil and emoteNames[oldAnim] == false then
		oldAnim = "idle"
	end
	currentAnim = ""
	currentAnimInstance = nil
	if currentAnimKeyframeHandler ~= nil then
		currentAnimKeyframeHandler:Disconnect()
	end
	if currentAnimTrack ~= nil then
		currentAnimTrack:Stop()
		currentAnimTrack:Destroy()
		currentAnimTrack = nil
	end
	return oldAnim
end

setAnimationSpeed = function(speed)
	if speed ~= currentAnimSpeed then
		currentAnimSpeed = speed
		currentAnimTrack:AdjustSpeed(currentAnimSpeed)
	end
end

keyFrameReachedFunc = function(frameName)
	if frameName == "End" then
		local repeatAnim = currentAnim
		if emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false then
			repeatAnim = "idle"
		end
		local animSpeed = currentAnimSpeed
		playAnimation(repeatAnim, 0.0, Humanoid)
		setAnimationSpeed(animSpeed)
	end
end

playAnimation = function(animName, transitionTime, humanoid) 
	local roll = math.random(1, animTable[animName].totalWeight) 
	local origRoll = roll
	local idx = 1
	while roll > animTable[animName][idx].weight do
		roll = roll - animTable[animName][idx].weight
		idx = idx + 1
	end
	local anim = animTable[animName][idx].anim
	if anim ~= currentAnimInstance then
		if currentAnimTrack ~= nil then
			currentAnimTrack:Stop(transitionTime)
			currentAnimTrack:Destroy()
		end
		currentAnimSpeed = 1.0
		currentAnimTrack = humanoid:LoadAnimation(anim)
		currentAnimTrack.Priority = Enum.AnimationPriority.Core
		currentAnimTrack:Play(transitionTime)
		currentAnim = animName
		currentAnimInstance = anim
		if currentAnimKeyframeHandler ~= nil then
			currentAnimKeyframeHandler:Disconnect()
		end
		currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:Connect(keyFrameReachedFunc)
	end
end

onRunning = function(speed)
	speed /= getRigScale()
	if speed > 0.01 then
		playAnimation("walk", 0.1, Humanoid)
		if currentAnimInstance and currentAnimInstance.AnimationId == "http://www.roblox.com/asset/?id=180426354" then
			setAnimationSpeed(speed / 14.5)
		end
		pose = "Running"
	else
		if emoteNames[currentAnim] == nil then
			playAnimation("idle", 0.1, Humanoid)
			pose = "Standing"
		end
	end
end

onDied = function()
	pose = "Dead"
end

onJumping = function()
	playAnimation("jump", 0.1, Humanoid)
	jumpAnimTime = jumpAnimDuration
	pose = "Jumping"
end

onClimbing = function(speed)
	speed /= getRigScale()
	playAnimation("climb", 0.1, Humanoid)
	setAnimationSpeed(speed / 12.0)
	pose = "Climbing"
end

onGettingUp = function()
	pose = "GettingUp"
end

onFreeFall = function()
	if jumpAnimTime <= 0 then
		playAnimation("fall", fallTransitionTime, Humanoid)
	end
	pose = "FreeFall"
end

onFallingDown = function()
	pose = "FallingDown"
end

onSeated = function()
	pose = "Seated"
end

onPlatformStanding = function()
	pose = "PlatformStanding"
end

onSwimming = function(speed)
	if speed > 0 then
		pose = "Running"
	else
		pose = "Standing"
	end
end

configureAnimationSet = function(name, fileList)
	if animTable[name] ~= nil then
		for _, connection in pairs(animTable[name].connections) do
			connection:Disconnect()
		end
	end
	animTable[name] = {}
	animTable[name].count = 0
	animTable[name].totalWeight = 0	
	animTable[name].connections = {}
	local config = script:FindFirstChild(name)
	if config ~= nil then
		table.insert(animTable[name].connections, config.ChildAdded:Connect(function(child) configureAnimationSet(name, fileList) end))
		table.insert(animTable[name].connections, config.ChildRemoved:Connect(function(child) configureAnimationSet(name, fileList) end))
		local idx = 1
		for _, childPart in pairs(config:GetChildren()) do
			if childPart:IsA("Animation") then
				table.insert(animTable[name].connections, childPart.Changed:Connect(function(property) configureAnimationSet(name, fileList) end))
				animTable[name][idx] = {}
				animTable[name][idx].anim = childPart
				local weightObject = childPart:FindFirstChild("Weight")
				if weightObject == nil then
					animTable[name][idx].weight = 1
				else
					animTable[name][idx].weight = weightObject.Value
				end
				animTable[name].count = animTable[name].count + 1
				animTable[name].totalWeight = animTable[name].totalWeight + animTable[name][idx].weight
				idx = idx + 1
			end
		end
	end
	if animTable[name].count <= 0 then
		for idx, anim in pairs(fileList) do
			animTable[name][idx] = {}
			animTable[name][idx].anim = Instance.new("Animation")
			animTable[name][idx].anim.Name = name
			animTable[name][idx].anim.AnimationId = anim.id
			animTable[name][idx].weight = anim.weight
			animTable[name].count = animTable[name].count + 1
			animTable[name].totalWeight = animTable[name].totalWeight + anim.weight
		end
	end
end

scriptChildModified = function(child)
	local fileList = animNames[child.Name]
	if fileList ~= nil then
		configureAnimationSet(child.Name, fileList)
	end	
end

initializeCharacter = function(character)
	Figure = character
	Humanoid = character:WaitForChild("Humanoid")
	local animator = Humanoid:FindFirstChildOfClass("Animator")
	if animator then
		local animTracks = animator:GetPlayingAnimationTracks()
		for _, track in ipairs(animTracks) do
			track:Stop(0)
			track:Destroy()
		end
	end
	for name, fileList in pairs(animNames) do 
		configureAnimationSet(name, fileList)
	end	
	Humanoid.Died:Connect(onDied)
	Humanoid.Running:Connect(onRunning)
	Humanoid.Jumping:Connect(onJumping)
	Humanoid.Climbing:Connect(onClimbing)
	Humanoid.GettingUp:Connect(onGettingUp)
	Humanoid.FreeFalling:Connect(onFreeFall)
	Humanoid.FallingDown:Connect(onFallingDown)
	Humanoid.Seated:Connect(onSeated)
	Humanoid.PlatformStanding:Connect(onPlatformStanding)
	Humanoid.Swimming:Connect(onSwimming)
	playAnimation("idle", 0.1, Humanoid)
	pose = "Standing"
end

LocalPlayer.CharacterAdded:Connect(initializeCharacter)
if LocalPlayer.Character then
	initializeCharacter(LocalPlayer.Character)
end