Having Trouble with AnimationTrack:Play()

So Im having issues about the Animator not working properly on a Npc, the Animator somehow doesnt play the animations I want and this is bugging me, nothing works!

I’ve tryed putting the script lines on a “script”, “Local script”, looked trough the roblox forum (and the recent change on the animator), i used the original animation script from the Lua Developer.

This script I putted is the Local Script that i putted in the player’s character to manage mine Npc, and i cutted half of it to resume the problem im having (And if there are more end's or lines than it appears, dont care about that)

The problem is indicated on the line marked with a “1”

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")

local CutsceneGui = PlayerGui:WaitForChild("CutsceneGui")
local Frame = CutsceneGui.Frame
local TextBox = Frame:FindFirstChild("WriteOn")

local CutscenePreps = require(script:WaitForChild("CutscenePreps"))

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local CtscnReceiver = ReplicatedStorage:WaitForChild("CtscnReceiver")
local CtscnSender = ReplicatedStorage:WaitForChild("CtscnSender")

local GameNpcs = workspace:WaitForChild("GameCharacters")
local Npc1 = GameNpcs:FindFirstChild("Npc1")
local Npc2 = GameNpcs:FindFirstChild("Npc2")

local Npc1Files = script.Parent:WaitForChild("ForNpc1")
local Npc2Files = script.Parent:WaitForChild("ForNpc2")
local PlayerFiles = script.Parent:WaitForChild("ForPlayer")

local CameraTweening = false
local Finished = false
local Running = false



local function WhenRequested(player, Files, CameraCframes)
	if not Running then
		Running = true
		Finished = false
		local Number = 1
		local ChosenAnimation1
		local ChosenAnimation2
		local ChosenAnimationPlayer
		local ChosenLinePlayer
		local CurrentCmrCframe
		local ChosenLine1
		local ChosenLine2
		local TimePlayed1
		local TimePlayed2
		local TimePlayedPlayer
		local WaitTime1
		local WaitTime2
		local WaitTimePlayer

		while not Finished do
			wait(1)
			local CharactersAnmQuantity = {Files.Npc1Animations:GetChildren(), Files.Npc2Animations:GetChildren(), Files.PlayerAnimations:GetChildren()}
			local CharactersLineQuantity = {Files.Npc1Lines, Files.Npc2Lines, Files.PlayerLines}
		
			while not (Number >= #CharactersAnmQuantity) and not (Number >= #CharactersLineQuantity) do
				ChosenAnimation1 = Files.Npc1Animations[Number]
				ChosenAnimation2 = Files.Npc2Animations[Number]
				ChosenLine1 = Files.Npc1Lines[Number]
				ChosenLine2 = Files.Npc2Lines[Number]
				ChosenAnimationPlayer = Files.PlayerAnimations[Number]
				ChosenLinePlayer = Files.PlayerLines[Number]
				CurrentCmrCframe = Files.CameraCframes[Number]
				TimePlayed1 = Files.Npc1TextFiles:FindFirstChild(Number)
				TimePlayed2 = Files.Npc2TextFiles:FindFirstChild(Number)
				TimePlayedPlayer = Files.PlayerTextFiles:FindFirstChild(Number)
				WaitTime1 = TimePlayed1:FindFirstChild("WaitTime")
				WaitTime2 = TimePlayed2:FindFirstChild("WaitTime")
				WaitTimePlayer = TimePlayedPlayer:FindFirstChild("WaitTime")
				Files.Npc1Animations:SetAttribute(ChosenAnimation1)
				Files.Npc2Animations:SetAttribute(ChosenAnimation2)
				Files.PlayerAnimations:SetAttribute(ChosenAnimationPlayer)


				local Humanoid1 = Npc1:FindFirstChild("Humanoid")
				local Animator1 = Instance.new("Animator", Humanoid1)

1				if tonumber(ChosenAnimation1.Name) == Number then
					local Load = Animator1:LoadAnimation(ChosenAnimation1)
					Load.Priority = Enum.AnimationPriority.Core
				Load:Play()
					if tonumber(ChosenLine1.Name) == Number then
						repeat
							wait(0.1)
						until ChosenAnimation1.TimePosition == TimePlayed1
						if ChosenAnimation1.TimePosition == TimePlayed1 then
							CutscenePreps.PlayLines(ChosenLine1, WaitTime1)
						end
					end	
					Number = Number + 1
		end	
		Running = false
	end	
end

I just briefly skimmed through this but I think your trying to load this animation into the Animator Object. You load the Animation into the actual Humanoid so in this case

Humanoid1:LoadAnimation(ChosenAnimation1)

If the Local script is located on the StarterPlayerScript, is it a matter? (Still not works that why im saying)

If this script applies on a NPC, it will probably be placed in the workspace, and only server scripts (not local scripts) can work there.
At line 2, you use the ‘LocalPlayer’ property of the Players service, which can’t be used in server scripts since it’s not about a specific client.

Edit : nevermind, just noticed it’s about the character of a player. My mistake

2 Likes

Yes, unless the script is located in game.Players.LocalPlayer it is most of the time the same between Players and NPC’s

1 Like

Just a recap, animations played through local scripts will also be played through the server.

I’ve looked and the script is located on there, what should i do in your opinion? (Yes it is a local script)

Its okay, suggest anything more?

simple stuff

the Animator1 that I underlined in red, Change to the Humanoid1 Variable and also remove that pesky little 1. That could ruin your entire script

1 Like

That 1 was just to indicate don’t worry, and well i tryed that as you asked, should i keep the HumanoidRootPart Anchored or not? I forgot to ask that

It doesn’t matter if the HumanoidRootPart it anchored or not, you can’t animate that on a Character. Even so if something is anchored it won’t stop it from moving

1 Like

Well… still it doesnt work oof

1 Like

I probably should have asked at the start, what does it say in the output?

1 Like

Actually it doesnt output any error, and yet character doesnt move (Do you want images of me testing it?)

1 Like

That would be great, I would say just yes but dev forum limit

1 Like

Yikes, should i put this as an engine bug?

1 Like

You defined ChosenAnimation1 twice in the same block

1 Like

Actually that’s possible to do! You can change values in the same thread, and don’t worry im not saying random stuff i actually check on a script inside the actual npc with a Instance “Animation”
(Nope it doesnt affect the script at all! I don’t remember where i learned this but you can search somewhere!)

1 Like

I understand, but I was just wondering if that by any chance could affect the script

1 Like

Try placing a print near the LoadAnimation Area, it might not even reach that zone

1 Like