Animation becomes Nil after firing or even after just not playing animation for a while

I have a few animations are supposed to play as you equip, idle, shoot, but for some reason, they become NIL after I equip the gun or wait a second too long.

(I have two weapons, my “Laser Musket” and “Hand Cannon”, my Laser Musket has NO issues and its PERFECT, but my HAND CANNON is what is breaking, despite both sharing basically the same code.)

A video to see what I mean.

I dont have an inkling of what this could be caused by, I’ve tried every solution–and it’d be helpful to know if anyone has had similar issues, if you have any inquiries please LMK…

(Handcannon Code so you can see that I am not loading the animation and playing it at the same time)

	Animations = AnimationTable
	Configuration = Config
	HumanoidRootPart = RootPart
	Humanoid = Soul
	
	coroutine.wrap(function()
		while task.wait(0.1) do
			for _, element in ipairs(AnimationTable) do
				warn(element)
			end
		end
	end)()
	
	print(Tool, AnimationTable, Config, RootPart, Soul)
		
	Weapon.Equipped:Connect(function()
		print("I SHOULD FIRE...?")
		
		Animations["EquipH"]:Play()
		
		task.wait(0.15)

		Animations["IdleH"]:Play()
		
		Humanoid.AutoRotate = false
		
		Connection = RunService.RenderStepped:Connect(function()
			if Humanoid.Health <= 0 then return end
			
			local MousePosition = Mouse.Hit.Position
			
			local LookToV3 = Vector3.new(MousePosition.X, HumanoidRootPart.CFrame.Y, MousePosition.Z)

			HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame.Position, LookToV3)
		end)
	end)
1 Like

The script provided is quite vague as it only shows a portion of your script… How do you get your module (did you use require)? What is animation table and config? How are they defined locally?

The module works fine, as I’ve said I am reusing a previous weapon module, (Laser Musket) to run my functions–dont really see the need for the entire script since the core issue lies with the animation, not the code–My animator table is a returned result from another module that I wrote that loads all the animations my client would need, which ill attach below, config does not matter.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Animations = ReplicatedStorage:WaitForChild("Animations")
local Tools = Animations:WaitForChild("Tools")

local AnimationLoader = {}

local LoadedAnimations = {}
local Group = {}

function AnimationLoader:LoadWeaponAnimations(Weapon, Humanoid)
	local Animator = Humanoid:WaitForChild("Animator")
	local AnimationIDsToLoad = Tools[Weapon]:GetChildren()
	
	table.clear(Group)
	
	for _, Animation in pairs(AnimationIDsToLoad) do
		
		--if table.find(LoadedAnimations, Animation) then
		--	print("Already Loaded")
		--	Group[Animation.Name] = Animation
		--end
		
		local AnimationTrack = Animator:LoadAnimation(Animation)
		Group[Animation.Name] = AnimationTrack
		
		LoadedAnimations[Animation.Name] = AnimationTrack
	end
	
	return Group
end

return AnimationLoader

I’d assume that it cant find the animations in the AnimationTable.
Is it spelled correctly?
is it in the table?

The animations are found and, as evidently shown in the video, will play and work–the issue is that they become NIL for reasons that have yet to be found. :exploding_head:

what lines error out, i cant tell due to the script only being a portion

No line errors out except for the lines that call the animation to play or stop, because the script reads them as nil…

image
I do ask to not speak on the issue if you cant atleast infer what the error details.

The issue does not SIT with the HANDLER(MODULE) of the GUN, as proven by the Laser Musket (A SEPERATE GUN WITH THE EXACT SAME CODE THAT STILL WORKS), The Point of the post is to help identify why animations are becoming nil (an issue also NOT present with the Laser Musket)

index nil means that the object your looking for doesnt exist.
i dont have the full script so i cant test it myself.

here are a few tips i use for debugging.

try printing the table to see if it includes it

try printing the Animations[“EquipH”] to see what it returns

try looking to see if anything overrides the value

im sorry if i cannot be of much help.

I am aware what nil means, all those debugs were already attempted
Its alright

and if worst comes to worst and you cant figure out the issue, you can directly calling an animation instance instead of using a table.

I’ll be on my way now

1 Like

Solution found, it was an issue of the animations not being given enough time to load.

I’ve rechecked both your code several times over… I don’t really see a problem with both of them… Since you’ve mentioned that the animations play anyway, even though they return nil…

I think the problem is with the animation or animationtrack itself… Although I’m not sure exactly what the problem is. I’m quite confused too since I’m not able to outright test your script. Sorry if I’m not able to help.

(nvm u already found the solution lol)

1 Like

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