-
What do you want to achieve?
I want player to have a animation when they are holding a gun. -
What is the issue?
When I reset my character it does not work and the “Cannot load the AnimationClipProvider Service” error pops up
this is my script, the error is at line:
[“CharacterHOLD”] = char:WaitForChild(“Humanoid”):LoadAnimation(viewModel.CharacterAnimations.Hold)
local gun = script.Parent
local runServce = game:GetService("RunService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local viewModel = replicatedStorage:WaitForChild("MainGame"):WaitForChild("Guns"):WaitForChild("Pistol"):Clone()
local camera = workspace.CurrentCamera
local plr = players.LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
viewModel.Parent = replicatedStorage.UnequippedGuns
local config = require(viewModel:WaitForChild("Config"))
local cf = CFrame.new()
local equipConnection
local walkAnimationSpeed = 5
local walkAnimationSize = 4
local recoilSpeed = 10
local recoilSize = 4
local shoot_cd = false
local isHolding = false
local isEquipped = false
local animations = {
["Hold"] = viewModel.AnimationController.Animator:LoadAnimation(viewModel.Animations.Hold),
["CharacterHOLD"] = char:WaitForChild("Humanoid"):LoadAnimation(viewModel.CharacterAnimations.Hold)
}
function positionModel()
local Humanoid = char:WaitForChild("Humanoid")
if Humanoid then
if Humanoid.MoveDirection.Magnitude > 0 then
cf = camera.CFrame*config.Offset_From_Camera
else
cf = camera.CFrame*config.Offset_From_Camera
end
viewModel:SetPrimaryPartCFrame(cf)
end
end
function shoot(target)
if not shoot_cd then
shoot_cd = true
if plr.Character:FindFirstChild(script.Parent.Name) then
local sin = math.sin(time() * recoilSpeed)/recoilSize
cf =cf:Lerp(CFrame.new(config.Offset_From_CameraX, config.Offset_From_Camera.Y, config.Offset_From_Camera.Z+sin),.2)
viewModel.Shoot:Play()
end
if target.Parent:FindFirstChild("Humanoid") then
replicatedStorage.MainGame.Remotes.Shoot:FireServer(mouse.Target, gun.Name)
end
wait(config.CoolDown_Each_Click)
shoot_cd = false
end
end
gun.Activated:Connect(function()
if config.IsAutomatic == false then
shoot(mouse.Target)
end
end)
mouse.Button1Down:Connect(function()
if config.IsAutomatic == true then
isHolding = true
end
end)
mouse.Button1Up:Connect(function()
if config.IsAutomatic == true then
isHolding = false
end
end)
local function equip()
if not gun and viewModel then return end
for _, part in pairs(gun:GetChildren()) do
if part:IsA("BasePart") or part:IsA("UnionOperation") then
part.Transparency = 1
end
end
viewModel.Parent = camera
animations["Hold"]:Play()
animations["CharacterHOLD"]:Play()
equipConnection = runServce.RenderStepped:Connect(function()
positionModel()
end)
end
local function unequip()
if not gun then return end
equipConnection:Disconnect()
viewModel.Parent = replicatedStorage.UnequippedGuns
animations["CharacterHOLD"]:Stop()
end
gun.Equipped:Connect(function()
mouse.Icon = "http://www.roblox.com/asset?id=9947945465"
isEquipped = true
equip()
end)
gun.Unequipped:Connect(function()
isEquipped = false
unequip()
mouse.Icon = "rbxasset://SystemCursors/Arrow"
end)
runServce.RenderStepped:Connect(function()
if isHolding == true then
shoot(mouse.Target)
end
end)