I’ll just leave the whole code here (localscript in tool):
local Player = game:GetService("Players").LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:Wait();
local Humanoid = Character:WaitForChild("Humanoid");
local PlayerGui = Player.PlayerGui;
local Camera = workspace.CurrentCamera;
local RunService = game:GetService("RunService");
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local UserInputService = game:GetService("UserInputService");
local SpringModule = require(ReplicatedStorage:WaitForChild("Spring"));
local EquipAnimation = Instance.new("Animation");
EquipAnimation.Parent = script.Parent;
EquipAnimation.AnimationId = "rbxassetid://12512430973"
EquipAnimation = Character:WaitForChild("Humanoid"):LoadAnimation(EquipAnimation);
EquipAnimation:SetAttribute("ViewModelAnimation", true);
local ViewModelStorage = ReplicatedStorage:WaitForChild(Player.Name.."ViewModelStorage")
local ViewModel = Camera:FindFirstChild("ViewModel") or ViewModelStorage:FindFirstChild("ViewModel");
local Offset = Character:WaitForChild("ViewModelController"):WaitForChild("Offset");
local AimSpring = SpringModule.new(0)
AimSpring.Damper = 1
AimSpring.Speed = 20;
-- the faster the speed the faster the gun aims down sights
local Recoil = SpringModule.new(Vector3.new())
Recoil.Speed = 100
-- the lower the recoil speed, the more the gun kicks
local CamRecoil = SpringModule.new(0)
CamRecoil.Speed = 20;
CamRecoil.Damper = 0.8
-- the lower the speed, the more camera recoil there is
-- the lower the damper, the more bounce there is
local PreviousCamTransform = CFrame.new();
local Handle = script.Parent:WaitForChild("Handle");
local AimPart = script.Parent:WaitForChild("AimPart");
local Aiming = false;
local Gun = script.Parent;
local Muzzle = Gun.Muzzle;
local FireSound = Muzzle:WaitForChild("Fire");
local GunEquipped = false;
function SetRightGripPart0(RightGrip, RightHand)
RightGrip.Part0 = RightHand
end
function FireGun()
FireSound:Play();
if (Gun.Parent ~= Character) then return
else
Recoil.Velocity = Vector3.new(0, 0, 12)
CamRecoil.Velocity = 100
end
end
function EquipGun()
EquipAnimation:Play();
GunEquipped = true
EquipAnimation:GetMarkerReachedSignal("AnimationPause"):Connect(function(Anim)
EquipAnimation:AdjustSpeed(0);
end)
end
script.Parent.Equipped:Connect(EquipGun);
function CheckFirstPerson()
if Character.Head.LocalTransparencyModifier > 0.6 then
return true
else
return false
end
end
function UnequipGun()
Offset.Value = CFrame.new()
GunEquipped = false;
ViewModel.Parent = ViewModelStorage;
EquipAnimation:Stop();
local Animations = ViewModel.Humanoid:GetPlayingAnimationTracks();
for _, ViewModelAnimation in ipairs(Animations) do
ViewModelAnimation:Stop();
end
end
Gun.Unequipped:Connect(UnequipGun);
function UpdateViewModel()
if (script.Parent.Parent ~= Character) then
AimSpring.Position = 0
return
else
local RightGrip = Character.RightHand:WaitForChild("RightGrip");
local InFirstPerson = CheckFirstPerson();
if InFirstPerson and RightGrip.Part0 ~= ViewModel.RightHand then
RightGrip.Part0 = ViewModel.RightHand;
print("Set grip to viewmodel")
ViewModel.Parent = Camera;
end
if not InFirstPerson and RightGrip.Part0 ~= Character.RightHand then
RightGrip.Part0 = Character.RightHand;
print("Set grip to character")
ViewModel.Parent = ViewModelStorage;
end
local CamTransform = CFrame.fromEulerAnglesXYZ(math.rad(CamRecoil.Position), 0, 0)
Camera.CFrame = Camera.CFrame * (CamTransform * PreviousCamTransform:Lerp(CFrame.new(), 0.02):Inverse())
PreviousCamTransform = CamTransform
local HandleTransform = ViewModel:GetPrimaryPartCFrame():ToObjectSpace(Handle.CFrame)
local OriginalTransform = HandleTransform * CFrame.new(Recoil.Position) * HandleTransform:Inverse()
local AimTransform = AimPart.CFrame:ToObjectSpace(Handle.CFrame) * CFrame.new(Recoil.Position) * HandleTransform:Inverse()
Offset.Value = OriginalTransform:Lerp(AimTransform, AimSpring.Position)
if Aiming then
AimSpring.Target = 1
else
AimSpring.Target = 0
end
end
end
RunService.RenderStepped:Connect(UpdateViewModel);
UserInputService.InputBegan:Connect(function(Input, GameProcessed)
if Input.UserInputType == Enum.UserInputType.MouseButton2
and Character.Head.LocalTransparencyModifier > 0.6 then
Aiming = true;
Humanoid.WalkSpeed = 5;
UserInputService.MouseIconEnabled = false;
end
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
FireGun();
end
end)
UserInputService.InputEnded:Connect(function(Input, GameProcessed)
if Input.UserInputType == Enum.UserInputType.MouseButton2
and Character.Head.LocalTransparencyModifier > 0.6 then
Aiming = false;
Humanoid.WalkSpeed = 16;
UserInputService.MouseIconEnabled = true;
end
end)
The error message “Cannot load the AnimationClipProvider Service” suggests that there may be an issue with the animation clip provider service in your game, which is responsible for loading and playing animations.
One potential solution is to try and manually load the AnimationClipProvider service before calling the LoadAnimation() function. You can do this using the following code:
local AnimationClipProvider = game:GetService("AnimationClipProvider")
Then, before calling LoadAnimation(), you can try setting the AnimationClipProvider property of the Humanoid object to the AnimationClipProvider service:
I think this might be an engine bug. Just found another dev forum posting with many people claiming to have suddenly encountered this same issue with their code despite no edits.