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!