I want to load animation into an object value

I want to load animation into an object value, so that I can use it anywhere later, I think it’s very convenient, but for some reason the script gives an error

LoadAnimation to object value

do
dummyHRP = dummy:WaitForChild(“HumanoidRootPart”)
dummyHum = dummy:WaitForChild(“Humanoid”)
local run = dummy:WaitForChild(“Run”)
local kick = dummy:WaitForChild(“Kick”)

dummy.Parent = workspace.NPC.Zombie
dummy.RunAnim.Value = dummyHum:LoadAnimation(run)
dummy.KickAnim.Value = dummyHum:LoadAnimation(kick)
dummy.KickAnim.Value:Play()
dummy.RunAnim.Value:Play()
end

Then in other script Run this

while true do
	--print( dummys)
	local dumHum = dummy:FindFirstChild("Humanoid")
	local dumHRP = dummy:FindFirstChild("HumanoidRootPart")
	local pathParts = dummy:FindFirstChild("PathParts")



	if dumHum and dumHRP and girlHRP  then
		--dumHum:MoveTo(girlHRP.Position)


		local closestChr = funcMod.getClosestChrPos(dumHRP.Position)

		if closestChr then 


			if dummy.Name == "ZombieZ" then 

				if (dumHRP.Position - closestChr.HumanoidRootPart.Position).Magnitude < 15 then

					--print(111)
					local soundZombie = dumHRP:FindFirstChild("SoundZombie")
					if soundZombie then 
						if not soundZombie.IsPlaying then 
							soundZombie:Play()
						end
					end

				

					dummy.RunAnim.Value:Stop()
					dummy.KickAnim.Value:Play()
					task.wait(2)
					dummy.KickAnim.Value:Stop()
					dummy.RunAnim.Value:Play()

Get error
ServerScriptService.Main:85: attempt to index nil with ‘Play’

how this objValue can be nill ? dummy.KickAnim.Value

I don’t think you can save it as an object value but you could save it in _G or shared.
Maybe make a table dedicated to that.

question is : why would you want to store it in an object value in the first place? It’s not convenient whatsoever and I’m sure you’re better off using just a normal animation. Could you try and remove the ObjectValue and only call the anim? If it’s nil that way too, then it’s a code error

it works for the first minute in the while loop, then for some reason it becomes nil, it seems that there is a limit on the number of calls

Could be breaking it because you’re essentially playing and stopping it infinitely, but that won’t result in the animation just disappearing lmao

It looks like you can’t load the animation this way, it’s a pity, it would be convenient

dummy.RunAnim.Value = dummyHum:LoadAnimation(run)
dummy.KickAnim.Value = dummyHum:LoadAnimation(kick)

After this loading, I look in the workspace there objectValue .Value is nil

Although it’s strange, because animation is an object)))