Animation won't play after character reset

Hello! I’m working on a third-person shooter framework. However, everytime I die with the gun, the animation refuses to play. I get this error

“Cannot load the AnimationClipProvider Service.”

Here is the client script:

--//Player BS
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid: Humanoid = char:WaitForChild("Humanoid")

local mouse = player:GetMouse()

--//Services
local userInputService = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")

--//Modules
local keybinds = require(script.Configuration:WaitForChild("Keybinds"))

local modules = replicatedStorage:WaitForChild("modules")
local gunFramework = modules:WaitForChild("gunFramework")
local weaponConstructor = require(gunFramework:WaitForChild("constructWeapon"))

local currentWeapon

--//Inventory
local inventory = {
	currentGun = nil,
	primary = "Pistol", 
	secondary = "Shotgun",
	melee = "Knife",
}

local function loadSlot(weapon)
	if weapon ~= inventory.currentGun then
		local char = player.Character or player.CharacterAdded:Wait()
		local humanoid: Humanoid = char:WaitForChild("Humanoid")

		inventory.currentGun = weapon
		print(inventory.currentGun)
		print("Loaded "..weapon)

		currentWeapon = weaponConstructor.Construct(weapon)
		currentWeapon:Equip()
	else
		print(inventory.currentGun)
		currentWeapon:Destroy()
		currentWeapon = nil
		inventory.currentGun = nil
	end	
end

userInputService.InputBegan:Connect(function(input, gp)
	if gp then return end
	
	if input.KeyCode == keybinds.primary then
		loadSlot(inventory.primary)
	elseif input.KeyCode == keybinds.secondary then
		loadSlot(inventory.secondary)
	elseif input.KeyCode == keybinds.melee then
		loadSlot(inventory.melee)
	elseif input.KeyCode == keybinds.reload then
		if currentWeapon then
			currentWeapon:Reload()
		end
	end
end)

mouse.Button1Down:Connect(function()
	if currentWeapon then
		currentWeapon:Fire()
	end
end)

humanoid.Died:Connect(function()
	currentWeapon:Destroy()
	currentWeapon = nil
	inventory.currentGun = nil
end)

Here is the module script (constructWeapon)

--//Services
local replicatedStorage = game:GetService("ReplicatedStorage")
local runService = game:GetService("RunService")

--//Events
local lookEvent = replicatedStorage.Events:WaitForChild("LookEvent")

--//Module bs
local modules = replicatedStorage:WaitForChild("modules")
local gunFramework = modules:WaitForChild("gunFramework")
local utilities = require(gunFramework:WaitForChild("utilities"))
local modelConstructor = require(gunFramework:WaitForChild("addModel"))

--//Player stuff
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid: Humanoid = char:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera

local Torso = char:WaitForChild('Torso')
local Neck = Torso:WaitForChild('Neck')
local RightShoulder = Torso:WaitForChild('Right Shoulder')
local LeftShoulder = Torso:WaitForChild('Left Shoulder')

local origins = {
	neckOg = Neck.C0,
	LeftShoulderOrgnC0 = LeftShoulder.C0,
	RightShoulderOrgnC0 = RightShoulder.C0
}

--[ Module!!!! ]

local weaponConstructor = {}
weaponConstructor.__index = weaponConstructor

function createAnim(animName, id)
	local animation = Instance.new("Animation")
	animation.Name = animName
	animation.AnimationId = id
	print("animation")
	return animation
end

function weaponConstructor.Construct(name: string)
	local self = setmetatable({
		weapon = require(utilities.findWeaponModule(name)), -- weapon functionality
		data = require(utilities.findWeaponData(name)), -- weapon data (includes ammo, fire mode etc.)
		model = replicatedStorage.createGun:InvokeServer(name, char), --create model on the server and get it on the client too
		animations = {},
		connections = {}
	}, weaponConstructor)
	
	self.animations.Equip = humanoid.Animator:LoadAnimation(createAnim("Equip", self.weapon.Animations.Equip)) 
	self.animations.Idle =  humanoid.Animator:LoadAnimation(createAnim("Idle", self.weapon.Animations.Idle))
	
	self.connections["LookAtCam"] = runService.RenderStepped:Connect(function()
		local CameraCFrame = camera.CoordinateFrame
		local MouseOriginPosition = player:GetMouse().Origin.Position
		if humanoid.Health > 0 then
			lookEvent:FireServer(CameraCFrame, MouseOriginPosition, origins.neckOg, origins.LeftShoulderOrgnC0, origins.RightShoulderOrgnC0, false)
		end
	end)
	
	return self
end

function weaponConstructor:Equip()
	self.animations.Equip:Play()
	self.animations.Equip.Stopped:Wait()
	self.animations.Idle:Play()
end

function weaponConstructor:Fire()
	self.weapon:Fire()
end

function weaponConstructor:Reload()
	self.weapon:Reload()
end

function weaponConstructor:Destroy()
	for _, v in pairs(self.connections) do
		v:Disconnect()
	end
	for _, v in pairs(self.animations) do
		v:Stop()
	end
	self.model.Model:Destroy()
	self.animations = {}
	
	-- reset the head and arms
	local CameraCFrame = camera.CoordinateFrame
	local MouseOriginPosition = player:GetMouse().Origin.Position
	lookEvent:FireServer(CameraCFrame, MouseOriginPosition, origins.neckOg, origins.LeftShoulderOrgnC0, origins.RightShoulderOrgnC0, true)
end

return weaponConstructor

Any help would be appreciated. Thanks!

Unless I’m insanely stupid and somehow messed something up, where the error occurred, line 55 is empty, can you paste each line that gave an error?

1 Like
self.animations.Equip = humanoid.Animator:LoadAnimation(createAnim("Equip", self.weapon.Animations.Equip)) 

GunHandler also looks like its lines are off, can you give me line 38 and 52 of it?

currentWeapon = weaponConstructor.Construct(weapon)

loadSlot(inventory.primary)

they arent really relevant to my problem so ¯_(ツ)_/¯

I think something breaks ( or get destroyed ) when the character die

Maybe the Animator?
Can you check for it?

1 Like

Yup, fixed it by redefining the character and humanoid when the character spawns

1 Like

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