Animate script doesnt work inside of custom rig

Hey. I recently started work on a game that has multiple custom rigs, meaning it’s not r15 or r6. To animate these, i started by testing the system so i made one of the rigs called StarterCharacter and made an animate script for it. However, it seems to only work when the animate script is inside of StarterCharacterScripts, but not when it’s inside of the rig.

The issue with this, is that I will have multiple different rigs with different animations, so i need a system where i can have multiple Animate scripts

I tried making the animate script a serverscript, however it still only works inside of startercharacterscripts.

Here’s my animate script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DisableSprint = ReplicatedStorage:WaitForChild("DisableSprint")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

humanoid.CameraOffset = Vector3.new(0, 3, 0)

local IdleAnim = script:WaitForChild("Idle")
local IdleAnimTrack = humanoid.Animator:LoadAnimation(IdleAnim)

local WalkAnim = script:WaitForChild("Walk")
local WalkAnimTrack = humanoid.Animator:LoadAnimation(WalkAnim)

local RunAnim = script:WaitForChild("Run")
local RunAnimTrack = humanoid.Animator:LoadAnimation(RunAnim)

local JumpAnim = script:WaitForChild("Jump")
local JumpAnimTrack = humanoid.Animator:LoadAnimation(JumpAnim)

local DisabledAnim = script:WaitForChild("Disabled")
local DisabledAnimTrack = humanoid.Animator:LoadAnimation(DisabledAnim)

local BlinkAnim = script:WaitForChild("Blink")
local BlinkAnimTrack = humanoid.Animator:LoadAnimation(BlinkAnim)

local player = game.Players:GetPlayerFromCharacter(character)
local battery = player:WaitForChild("leaderstats"):WaitForChild("Battery")

local function PlayIdle()
	IdleAnimTrack:Play()
end

print('runnin')

humanoid.Running:Connect(function(speed)
	print('yolo 2')
	if battery.Value > 0 then
		if speed > 8 then
			if not RunAnimTrack.IsPlaying then
				RunAnimTrack:Play()
				WalkAnimTrack:Stop()
				IdleAnimTrack:Stop()
			end
		elseif speed > 0 then
			if not WalkAnimTrack.IsPlaying then
				WalkAnimTrack:Play()
				RunAnimTrack:Stop()
				IdleAnimTrack:Stop()
			end
		else
			if not IdleAnimTrack.IsPlaying then
				PlayIdle()
				WalkAnimTrack:Stop()
				RunAnimTrack:Stop()
			end
		end
	else
		WalkAnimTrack:Stop()
		RunAnimTrack:Stop()
	end
end)

humanoid.Jumping:Connect(function()
	if battery.Value > 0 and not JumpAnimTrack.IsPlaying then
		JumpAnimTrack:Play()
		task.wait(0.5)
		JumpAnimTrack:Stop()
	end
end)

battery:GetPropertyChangedSignal("Value"):Connect(function()
	if battery.Value <= 0 then
		PlayIdle()
		DisabledAnimTrack:Play()
		DisableSprint:Fire()
		task.wait(10)
		DisabledAnimTrack:Stop()
	end
end)

and here is my morphing script:

local AllowMorph = script.Parent:WaitForChild('AllowMorph')

local Survivors = script:WaitForChild('Survivors')
local Monsters = script:WaitForChild('Monsters')

local function PickRandom(parent)
	local Picked
	if parent then
		local children = parent:GetChildren()
		if #children > 0 then
			local randomIndex = math.random(1, #children)
			Picked = children[randomIndex]:Clone()
		else
			warn('No eligible pick found')
		end
	end
	return Picked
end

AllowMorph.Event:Connect(function(Player, Role)
	if Player and Role then
		local oldCharacter = Player.Character
		local newCharacter

		-- Handle roles (Monster or Survivor)
		if Role == 'Monster' then
			newCharacter = PickRandom(Monsters)
		elseif Role == 'Survivor' then
			newCharacter = PickRandom(Survivors)
		end

		if newCharacter then
			if oldCharacter then
				local oldPosition = oldCharacter:FindFirstChild("HumanoidRootPart") and oldCharacter.HumanoidRootPart.Position
				oldCharacter:Destroy()

				newCharacter.Parent = workspace
				Player.Character = newCharacter

				if oldPosition then
					newCharacter:SetPrimaryPartCFrame(CFrame.new(oldPosition))
				end

				local humanoid = newCharacter:FindFirstChild("Humanoid")
				local camera = workspace.CurrentCamera

				if humanoid then
					camera.CameraSubject = humanoid
					print("CameraSubject set to new character's humanoid.")
				else
					warn("New character missing Humanoid!")
				end

				for _, part in pairs(newCharacter:GetDescendants()) do
					if part:IsA("BasePart") then
						part.Anchored = false
					end
				end
			end
		else
			warn("Morph creation failed for role: " .. Role)
		end
	end
end)

The rigs are stored inside of ServerScriptService, then cloned and added to the workspace. The morphing works, the player’s old character is removed and they turn into the new rig, however with the Animate script not running

Thanks

Have you tried adding the Animate script after morphing the character?

Leave the script in StarterCharacterScripts, then change local character = script.Parent to local character = game.workspace:WaitForChild(“ModelName”)?

This made some of it work. However now the player doesn’t seem to be able to run, and it doesn’t play the run animation either. However the FOV gets changed in script 2

Animate script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DisableSprint = ReplicatedStorage:WaitForChild("DisableSprint")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

humanoid.CameraOffset = Vector3.new(0, 3, 0)

local IdleAnim = script:WaitForChild("Idle")
local IdleAnimTrack = humanoid.Animator:LoadAnimation(IdleAnim)

local WalkAnim = script:WaitForChild("Walk")
local WalkAnimTrack = humanoid.Animator:LoadAnimation(WalkAnim)

local RunAnim = script:WaitForChild("Run")
local RunAnimTrack = humanoid.Animator:LoadAnimation(RunAnim)

local JumpAnim = script:WaitForChild("Jump")
local JumpAnimTrack = humanoid.Animator:LoadAnimation(JumpAnim)

local DisabledAnim = script:WaitForChild("Disabled")
local DisabledAnimTrack = humanoid.Animator:LoadAnimation(DisabledAnim)

local BlinkAnim = script:WaitForChild("Blink")
local BlinkAnimTrack = humanoid.Animator:LoadAnimation(BlinkAnim)

local player = game.Players:GetPlayerFromCharacter(character)
local battery = player:WaitForChild("leaderstats"):WaitForChild("Battery")

local function PlayIdle()
	IdleAnimTrack:Play()
end

humanoid.Running:Connect(function(speed)
	if battery.Value > 0 then
		if speed > 8 then
			if not RunAnimTrack.IsPlaying then
				RunAnimTrack:Play()
				WalkAnimTrack:Stop()
				IdleAnimTrack:Stop()
			end
		elseif speed > 0 then
			if not WalkAnimTrack.IsPlaying then
				WalkAnimTrack:Play()
				RunAnimTrack:Stop()
				IdleAnimTrack:Stop()
			end
		else
			if not IdleAnimTrack.IsPlaying then
				PlayIdle()
				WalkAnimTrack:Stop()
				RunAnimTrack:Stop()
			end
		end
	else
		WalkAnimTrack:Stop()
		RunAnimTrack:Stop()
	end
end)

humanoid.Jumping:Connect(function()
	if battery.Value > 0 and not JumpAnimTrack.IsPlaying then
		JumpAnimTrack:Play()
		task.wait(0.5)
		JumpAnimTrack:Stop()
	end
end)

battery:GetPropertyChangedSignal("Value"):Connect(function()
	if battery.Value <= 0 then
		PlayIdle()
		DisabledAnimTrack:Play()
		DisableSprint:Fire()
		task.wait(10)
		DisabledAnimTrack:Stop()
	end
end)

And then this is the second script:
Script 2:

-- @ CasualCode

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local statusEvent = ReplicatedStorage:WaitForChild("statusEvent")
local statusLabel = script.Parent:WaitForChild("RoundLabel")

local leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats")
local role = leaderstats:WaitForChild("Role")

statusEvent.OnClientEvent:Connect(function(statusText)
	statusLabel.Text = statusText
end)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DisableSprint = ReplicatedStorage:WaitForChild("DisableSprint")

local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera

local DefaultFieldOFView = Camera.FieldOfView
local DefaultWalkingSpeed = Humanoid.WalkSpeed
local DefaultJumpPower = Humanoid.JumpPower

local MonsterSpeed = 22
local SurvivorSpeed = 12  
local Key = Enum.KeyCode.LeftShift
local TweenSpeed = 0.5

local SprintFOV = DefaultFieldOFView + 30 

local Battery = leaderstats:WaitForChild("Battery")

local Sprinting = false
local BatteryDepletionRate = 1

local SprintTween = TweenService:Create(Camera, TweenInfo.new(TweenSpeed), { FieldOfView = SprintFOV })
local DefaultTween = TweenService:Create(Camera, TweenInfo.new(TweenSpeed), { FieldOfView = DefaultFieldOFView })

local function StopSprinting()
	if not Sprinting then return end
	Sprinting = false
	Humanoid.WalkSpeed = DefaultWalkingSpeed
	DefaultTween:Play()
end

local function StartSprinting()
	if Sprinting or Battery.Value < 1 then return end
	Sprinting = true

	if role.Value == "Monster" then
		Humanoid.WalkSpeed = MonsterSpeed
	else
		Humanoid.WalkSpeed = SurvivorSpeed
	end

	
	SprintTween:Play()

	task.spawn(function()
		while Sprinting do
			if Battery.Value >= BatteryDepletionRate then
				Battery.Value -= BatteryDepletionRate
			else
				StopSprinting()
			end
			task.wait(0.1)
		end
	end)
end

local function SetSpeeds(W, J)
	if Humanoid then
		Humanoid.WalkSpeed = W
		Humanoid.JumpPower = J
	end
end

DisableSprint.Event:Connect(function()
	Sprinting = false
	SetSpeeds(0, 0)
	DefaultTween:Play()
	task.wait(10)
	SetSpeeds(DefaultWalkingSpeed, DefaultJumpPower)
end)

UIS.InputBegan:Connect(function(Input, Processed)
	if not Processed and Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Key then
		StartSprinting()
	end
end)

UIS.InputEnded:Connect(function(Input)
	if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Key then
		StopSprinting()
	end
end)


DefaultTween:Play()