Play an animation on viewmodel inside currentcamera through a tool's local script is difficult

Hello, i’ve been wanting to achieve to play Animation Tracks on a Skinned Mesh viewmodel on a FPS Game.
bandicam 2023-12-07 12-27-28-445
It works with an animation controller.
bandicam 2023-12-07 12-27-39-935

I’ve tried alot of ways like loading the animation on the viewmodel function, but it gives me this error: Cannot load the animation clip provider service.

However, it seems i have no way or enough knowledge to call the CurrentCamera’s ViewModel on a localscript through a variable and play the animation.
image

Is there a efficient way i can achieve this in This Local Script?

local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild("Humanoid")
--local TEAM = Player.Team
local VisualizeBullet = game.ReplicatedStorage:WaitForChild("VisualizeBullet")
local Module = require(Tool:WaitForChild("Setting"))
local GunScript_Server = Tool:WaitForChild("GunScript_Server")
local ChangeAmmoAndClip = GunScript_Server:WaitForChild("ChangeAmmoAndClip")
local InflictTarget = GunScript_Server:WaitForChild("InflictTarget")
local AmmoValue = GunScript_Server:WaitForChild("Ammo")
local ClipsValue = GunScript_Server:WaitForChild("Clips")
local GUI = script:WaitForChild("GunGUI")
local IdleAnim
local FireAnim
local ReloadAnim
local ShotgunClipinAnim
local Grip2
local Handle2
local HandleToFire = Handle
local Secondary = false
local vm = {nil}
local recoil = script.recoil

anim_p = {
	cam_offset = CFrame.new(0.45, -1.525, 0.9) * CFrame.Angles(math.rad(-90), math.rad(0), math.rad(0)),
	recoil_speed = 0,
	recoil_amp = 0,
	aim_amp = 0.5,
	aim_max_change = 4,
	aim_retract = 15,
	aim_max_deg = 20,
}
recoil.Value = false
local cam_weld = {nil}

if Module.DualEnabled then
	Handle2 = Tool:WaitForChild("Handle2",2)
	if Handle2 == nil and Module.DualEnabled then error("\"Dual\" setting is enabled but \"Handle2\" is missing!") end
end

local Equipped = false
local Enabled = true
local Down = false
local Reloading = false
local AimDown = false
local Ammo = AmmoValue.Value
local Clips = ClipsValue.Value
local MaxClip = Module.MaxClip
local PiercedHumanoid = {}
local fp = false

if Module.IdleAnimationID ~= nil or Module.DualEnabled then
	IdleAnim = Tool:WaitForChild("IdleAnim")
	IdleAnim = Humanoid:LoadAnimation(IdleAnim)
end
if Module.FireAnimationID ~= nil then
	FireAnim = Tool:WaitForChild("FireAnim")
	FireAnim = Humanoid:LoadAnimation(FireAnim)
end
if Module.ReloadAnimationID ~= nil then
	ReloadAnim = Tool:WaitForChild("ReloadAnim")
	ReloadAnim = Humanoid:LoadAnimation(ReloadAnim)
end
if Module.ShotgunClipinAnimationID ~= nil then
	ShotgunClipinAnim = Tool:WaitForChild("ShotgunClipinAnim")
	ShotgunClipinAnim = Humanoid:LoadAnimation(ShotgunClipinAnim)
end

function wait_(TimeToWait)
	if TimeToWait ~= nil then
		local TotalTime = 0
		TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
		while TotalTime < TimeToWait do
			TotalTime = TotalTime + game:GetService("RunService").Heartbeat:wait()
		end
	else
		game:GetService("RunService").Heartbeat:wait()
	end
end

function RayCast(Start,Direction,Range,Ignore)
	local Hit,EndPos = game.workspace:FindPartOnRay(Ray.new(Start,Direction*Range),Ignore)
	if Hit then
		if ((Hit.Parent:FindFirstChild("Humanoid")==nil)
			and (Hit.Transparency > 0.75
				or Hit.Name == "Handle"
				or Hit.Name == "Effect"
				or Hit.Name == "Bullet"
				or Hit.Name == "Laser"
				or string.lower(Hit.Name) == "water"
				or Hit.Name == "Rail"
				or Hit.Name == "Arrow")
			or (Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent.Humanoid.Health == 0)
			--[[or (Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("TEAM") and Character:FindFirstChild("TEAM") and Hit.Parent.TEAM.Value == Character.TEAM.Value)]])
				or (Hit.Parent:FindFirstChild("Humanoid") and PiercedHumanoid[Hit.Parent.Humanoid]) then
			Hit,EndPos = RayCast(EndPos+(Direction*.01),Direction,Range-((Start-EndPos).magnitude),Ignore)
		end
	end
	return Hit,EndPos
end

function ShakeCamera()
	if Module.CameraShakingEnabled then
		local Intensity = Module.Intensity/(AimDown and Module.MouseSensitive or 1)
		for i = 1, 10 do
			local cam_rot = Camera.CoordinateFrame - Camera.CoordinateFrame.p
			local cam_scroll = (Camera.CoordinateFrame.p - Camera.Focus.p).magnitude
			local ncf = CFrame.new(Camera.Focus.p)*cam_rot*CFrame.fromEulerAnglesXYZ((-Intensity+(math.random()*(Intensity*2)))/100, (-Intensity+(math.random()*(Intensity*2)))/100, 0)
			Camera.CoordinateFrame = ncf*CFrame.new(0, 0, cam_scroll)
			wait_()
		end
	end
end

function Fire(ShootingHandle)
	local PierceAvailable = Module.Piercing
	PiercedHumanoid = {}
	if FireAnim then FireAnim:Play(nil,nil,Module.FireAnimationSpeed) end
	--local fireindex = math.random(1,3)
	if not ShootingHandle.FireSound.Playing or not ShootingHandle.FireSound.Looped then ShootingHandle.FireSound.TimePosition = 0.05 ShootingHandle.FireSound:Play() end
	recoil.Value = true
	local Start = (Humanoid.Torso.CFrame * CFrame.new(0,1.5,0)).p--(Handle.CFrame * CFrame.new(Module.MuzzleOffset.X,Module.MuzzleOffset.Y,Module.MuzzleOffset.Z)).p
	local Spread = (Secondary and Module.SpreadSecondary) or Module.Spread*(AimDown and 1-Module.SpreadRedution or 1)
	local Direction = (CFrame.new(Start,Mouse.Hit.p) * CFrame.Angles(math.rad(-Spread+(math.random()*(Spread*2))),math.rad(-Spread+(math.random()*(Spread*2))),0)).lookVector
	while PierceAvailable >= 0 do
		local Hit,EndPos = RayCast(Start,Direction,5000,Character)
		if not Module.ExplosiveEnabled then
			if Hit and Hit.Parent then
				local TargetHumanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
				local TargetTorso = Hit.Parent:FindFirstChild("Torso")
				--local TargetTEAM
				if TargetHumanoid and TargetHumanoid.Health > 0 and TargetTorso then
					--[[if game.Players:GetPlayerFromCharacter(Hit.Parent)~=nil then
						TargetTEAM = game.Players:GetPlayerFromCharacter(Hit.Parent).Team
					end]]
					--if  game.Players:GetPlayerFromCharacter(Hit.Parent)==nil or (game.Players:GetPlayerFromCharacter(Hit.Parent)~=nil and TargetTEAM ~= TEAM) then
						InflictTarget:FireServer(TargetHumanoid,
												TargetTorso,
												(Hit.Name == "Head" and Module.HeadshotEnabled) and Module.BaseDamage * Module.HeadshotDamageMultiplier or Module.BaseDamage,
												Direction,
												Module.Knockback,
												Module.Lifesteal,
												Module.FlamingBullet,
												Hit)
						PiercedHumanoid[TargetHumanoid] = true
					--end
				else
					PierceAvailable = 0
				end
			end
		else
			local Explosion = Instance.new("Explosion")
			Explosion.BlastRadius = Module.Radius
			Explosion.BlastPressure = 0
			Explosion.Position = EndPos
			Explosion.Parent = workspace.CurrentCamera
			Explosion.Hit:connect(function(Hit)
				if Hit and Hit.Parent and Hit.Name == "Torso" then
					local TargetHumanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
					local TargetTorso = Hit.Parent:FindFirstChild("Torso")
					--local TargetTEAM
					if TargetHumanoid and TargetHumanoid.Health > 0 and TargetTorso then
						--[[if game.Players:GetPlayerFromCharacter(Hit.Parent)~=nil then
							TargetTEAM = game.Players:GetPlayerFromCharacter(Hit.Parent).Team
						end]]
						--if game.Players:GetPlayerFromCharacter(Hit.Parent)==nil or (game.Players:GetPlayerFromCharacter(Hit.Parent)~=nil and TargetTEAM ~= TEAM) then
							InflictTarget:FireServer(TargetHumanoid,
													TargetTorso,
													(Hit.Name == "Head" and Module.HeadshotEnabled) and Module.BaseDamage * Module.HeadshotDamageMultiplier or Module.BaseDamage,
													Direction,
													Module.Knockback,
													Module.Lifesteal,
													Module.FlamingBullet,
													Hit)
						--end
					end
				end
			end)
			PierceAvailable = 0
		end
		PierceAvailable = Hit and (PierceAvailable - 1) or -1
		Player.PlayerScripts.BulletVisualizerScript.Visualize:Fire(nil,ShootingHandle,
																	Module.MuzzleOffset,
																	EndPos,
																	script.MuzzleEffect,
																	script.HitEffect,
																	Module.HitSoundIDs[math.random(1,#Module.HitSoundIDs)],
																	{Module.ExplosiveEnabled,Module.BlastRadius,Module.BlastPressure},
																	{Module.BulletSpeed,Module.BulletSize,Module.BulletColor,Module.BulletTransparency,Module.BulletMaterial,Module.FadeTime},
																	false,
																	PierceAvailable == -1 and Module.VisualizerEnabled or false,
																	(vm[1]~=nil and vm[1].muzz) or nil,
																	fp)
		game.ReplicatedStorage.VisualizeBullet:FireServer(ShootingHandle,
														Module.MuzzleOffset,
														EndPos,
														script.MuzzleEffect,
														script.HitEffect,
														Module.HitSoundIDs[math.random(1,#Module.HitSoundIDs)],
														{Module.ExplosiveEnabled,Module.BlastRadius,Module.BlastPressure},
														{Module.BulletSpeed,Module.BulletSize,Module.BulletColor,Module.BulletTransparency,Module.BulletMaterial,Module.FadeTime},
														true,
														PierceAvailable == -1 and Module.VisualizerEnabled or false,
														nil,
														false)
		Start = EndPos + (Direction*0.01)
	end
end

function Reload()
	if Enabled and not Reloading and (Clips > 0 or not Module.LimitedClipEnabled) and Ammo < Module.AmmoPerClip then
		Reloading = true
		if AimDown then
			workspace.CurrentCamera.FieldOfView = 70
			--[[local GUI = game.Players.LocalPlayer.PlayerGui:FindFirstChild("ZoomGui")
			if GUI then GUI:Destroy() end]]
			GUI.Scope.Visible = false
			--game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
			script["Mouse Sensitivity"].Disabled = true
			AimDown = false
			Mouse.Icon = "rbxassetid://"..Module.MouseIconID
		end
		UpdateGUI()
		if Module.ShotgunReload then
			for i = 1,(Module.AmmoPerClip - Ammo) do
				if ShotgunClipinAnim then ShotgunClipinAnim:Play(nil,nil,Module.ShotgunClipinAnimationSpeed) end
				Handle.ShotgunClipin:Play()
				wait_(Module.ShellClipinSpeed)
			end
		end
		if ReloadAnim then ReloadAnim:Play(nil,nil,Module.ReloadAnimationSpeed) end
		Handle.ReloadSound:Play()
		wait_(Module.ReloadTime)
		if Module.LimitedClipEnabled then 
			if Clips - (Module.AmmoPerClip - Ammo) < 0 then
				Ammo = Ammo + Clips
				Clips = 0
			else
				Clips = Clips - (Module.AmmoPerClip - Ammo)
				Ammo = Module.AmmoPerClip
			end
		else
			Ammo = Module.AmmoPerClip
		end
		ChangeAmmoAndClip:FireServer(Ammo,Clips)
		Reloading = false
		UpdateGUI()
	end
end

function UpdateGUI()
	GUI.Frame.Ammo.Fill:TweenSizeAndPosition(UDim2.new(Ammo/Module.AmmoPerClip,0,1,0), UDim2.new(0,0,0,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 0.25, true)
	GUI.Frame.Clips.Fill:TweenSizeAndPosition(UDim2.new(Clips/Module.MaxClip,0,1,0), UDim2.new(0,0,0,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quint, 0.25, true)
	GUI.Frame.Ammo.Current.Text = (Secondary and "*"..Ammo) or Ammo
	GUI.Frame.Ammo.Max.Text = Module.AmmoPerClip
	GUI.Frame.Clips.Current.Text = Clips
	GUI.Frame.Clips.Max.Text = Module.MaxClip

	GUI.Frame.Ammo.Current.Visible = not Reloading
	GUI.Frame.Ammo.Max.Visible = not Reloading
	GUI.Frame.Ammo.Frame.Visible = not Reloading
	GUI.Frame.Ammo.Reloading.Visible = Reloading

	GUI.Frame.Clips.Current.Visible = not (Clips <= 0)
	GUI.Frame.Clips.Max.Visible = not (Clips <= 0)
	GUI.Frame.Clips.Frame.Visible = not (Clips <= 0)
	GUI.Frame.Clips.NoMoreClip.Visible = (Clips <= 0)
	
	GUI.Frame.Clips.Visible = Module.LimitedClipEnabled
	GUI.Frame.Size = Module.LimitedClipEnabled and UDim2.new(0,250,0,100) or UDim2.new(0,250,0,55)
	GUI.Frame.Position = Module.LimitedClipEnabled and UDim2.new(1,-260,1,-110)or UDim2.new(1,-260,1,-65)
end

function viewmodel()
	local head = Character.Head
	local torso = Character.HumanoidRootPart
	local camera = game.workspace.CurrentCamera
	
	local check = {torso:findFirstChild("vmweld")}
	if check[1] then check[1]:remove() end
	local check2 = {camera:findFirstChild("glockvm")}
	if check2[1] then check2[1].Parent = nil end

	
	vm[1] = game:GetService("ReplicatedStorage"):WaitForChild("ViewModels"):WaitForChild("glockvm"):Clone()
	
	cam_weld = {Instance.new("Weld")}
	cam_weld[1].Name = "vmweld"
	cam_weld[1].Part0 = Character.HumanoidRootPart
	cam_weld[1].Part1 = vm[1].PrimaryPart
	cam_weld[1].Parent = vm[1].PrimaryPart


	local last_va = 0
	local last_va2 = 0
	local view_velocity = {0, 0}
	
	local recoil_amm = 0
	local rec_con = recoil.Changed:connect(function()
		recoil.Value = false
		recoil_amm = 1
	end)
	
	local move_anim_speed = 3
	local last_p = Vector3.new()
	local move_amm = 0
	coroutine.resume(coroutine.create(function()
		while cam_weld[1] ~= nil and cam_weld[1].Parent ~= nil do
			local delta = wait(1/25)
			local cur_p = torso.Position
			if (cur_p - last_p).magnitude >= 0.1 then
				move_amm = math.min(1, move_amm + delta * move_anim_speed)
			else
				move_amm = math.max(0, move_amm - delta * move_anim_speed)
			end
			last_p = cur_p
		end
	end))
	
	local r_serv = game:GetService("RunService")

	coroutine.resume(coroutine.create(function()
		local last_time = tick()
		while cam_weld[1] ~= nil and cam_weld[1].Parent ~= nil do
			
			r_serv.RenderStepped:wait()
			local delta = tick() - last_time
			last_time = tick()
			
			local p_distance = (head.Position - Mouse.Hit.p).magnitude
			if p_distance == 0 then p_distance = 0.0001 end
			local p_height = Mouse.Hit.p.y - head.Position.y
			local view_angle 
			if p_height ~= 0 then
				view_angle = math.deg(math.asin(math.abs(p_height) / p_distance)) * (math.abs(p_height) / p_height)
			else
				view_angle = 0
			end

			local cam_cf = camera.CoordinateFrame
			local looking_at = cam_cf * CFrame.new(0, 0, -100)
			local view_angle2 = math.deg(math.atan2(cam_cf.p.x - looking_at.p.x, cam_cf.p.z - looking_at.p.z)) + 180

			local v_delta1, v_delta2
			local dir1 = 0
			local dir2 = 0
			v_delta1 = math.abs(view_angle - last_va)
			if v_delta1 ~= 0 then
				dir1 = (view_angle - last_va) / v_delta1
			end
			local va_check = {math.abs(view_angle2 - last_va2), 360 - math.abs(view_angle2 - last_va2)}
			if view_angle2 == last_va2 then
				dir2 = 0
				v_delta2 = 0
			elseif va_check[1] < va_check[2] then
				v_delta2 = va_check[1]
				dir2 = (view_angle2 - last_va2) / va_check[1]
			else
				v_delta2 = va_check[2]
				if last_va2 > view_angle2 then
					dir2 = 1
				else
					dir2 = -1
				end
			end
			last_va = view_angle
			last_va2 = view_angle2

			view_velocity[1] = view_velocity[1] / (1 + (delta * anim_p.aim_retract))
			view_velocity[2] = view_velocity[2] / (1 + (delta * anim_p.aim_retract))

			local calc1 = v_delta1 * dir1 * anim_p.aim_amp
			if calc1 ~= 0 then
				view_velocity[1] = view_velocity[1] + (math.min(anim_p.aim_max_change, math.abs(calc1)) * (calc1 / math.abs(calc1)))
			end
			local calc2 = v_delta2 * dir2 * anim_p.aim_amp
			if calc2 ~= 0 then
				view_velocity[2] = view_velocity[2] + (math.min(anim_p.aim_max_change, math.abs(calc2)) * (calc2 / math.abs(calc2)))
			end

			if view_velocity[1] ~= 0 then
				view_velocity[1] = math.min(anim_p.aim_max_deg, math.abs(view_velocity[1])) * (math.abs(view_velocity[1]) / view_velocity[1])
			end
			if view_velocity[2] ~= 0 then
				view_velocity[2] = math.min(anim_p.aim_max_deg, math.abs(view_velocity[2])) * (math.abs(view_velocity[2]) / view_velocity[2])
			end
			
			if vm[1] then
				if (head.Position - camera.CoordinateFrame.p).magnitude < 3 then
					if vm[1].Parent == nil then
						vm[1].Parent = camera
						
						
					end
					cam_weld[1].Parent = vm[1].PrimaryPart

					recoil_amm = math.max(0, recoil_amm - (delta / anim_p.recoil_speed))
					local recoil_deg = (recoil_amm * anim_p.recoil_amp * 7)
					local recoil_move = (recoil_amm * anim_p.recoil_amp / 4)
					
					local breathe_amp = 0
					local breathe_freq = 0
					local breathe = math.sin(math.rad(tick() * 90 * breathe_freq)) * breathe_amp

					local shake_freq = 0
					local shake_amp = {0, 0}
					local arm_shake = CFrame.new(
						math.sin(math.rad(tick() * 90 * shake_freq)) * move_amm * shake_amp[1],
						0,
						math.abs(math.sin(math.rad(tick() * 90 * shake_freq)) * move_amm * shake_amp[2]))

					local cam_cf = camera.CoordinateFrame * CFrame.Angles(math.rad(90 + (recoil_deg / 3) + (breathe / 2) - view_velocity[1]), 0, math.rad(view_velocity[2])) * arm_shake * CFrame.new(0, recoil_move, 0) * anim_p.cam_offset
					cam_weld[1].C0 = torso.CFrame:inverse() * cam_cf
					
					if Tool:FindFirstChild("w_glock").Transparency ~= 1 then
						Tool:FindFirstChild("w_glock").Transparency = 1
					end
					fp = true
				else
					fp = false
					if Tool:FindFirstChild("w_glock").Transparency ~= 0 then
						Tool:FindFirstChild("w_glock").Transparency = 0
					end
					
					if vm[1].Parent ~= nil then
						vm[1].Parent = nil
						
					end
				end
			end
		end
		rec_con:disconnect()
	end))
end

function endviewmodel()
	if cam_weld[1] then
		cam_weld[1]:remove()
		cam_weld[1] = nil
	end
	if vm[1] then
		vm[1]:remove()
		vm[1] = nil
	end
end
Mouse.Button1Down:connect(function()
	Down = true
	local IsChargedShot = false
	if Equipped and Enabled and Down and not Reloading and Ammo > 0 and Humanoid.Health > 0 then
		Enabled = false
		if Module.ChargedShotEnabled then
			if HandleToFire:FindFirstChild("ChargeSound") then HandleToFire.ChargeSound:Play() end
			wait_(Module.ChargingTime)
			IsChargedShot = true
		end
		if Module.MinigunEnabled then
			if HandleToFire:FindFirstChild("WindUp") then HandleToFire.WindUp:Play() end
			wait_(Module.DelayBeforeFiring)
		end
		while Equipped and not Reloading and (Down or IsChargedShot) and Ammo > 0 and Humanoid.Health > 0 do
			IsChargedShot = false
			for i = 1,(Module.BurstFireEnabled and Module.BulletPerBurst or 1) do
				Spawn(ShakeCamera)
				for x = 1,(Module.ShotgunEnabled and Module.BulletPerShot or 1) do
					Fire(HandleToFire)
				end
				Ammo = Ammo - 1
				ChangeAmmoAndClip:FireServer(Ammo,Clips)
				UpdateGUI()
				if Module.BurstFireEnabled then wait_(Module.BurstRate) end
				if Ammo <= 0 then break end
			end
			HandleToFire = (HandleToFire == Handle and Module.DualEnabled) and Handle2 or Handle
			wait_((Secondary and Module.FireRateSecondary) or Module.FireRate)
			if not Module.Auto then break end
		end
		if HandleToFire.FireSound.Playing and HandleToFire.FireSound.Looped then HandleToFire.FireSound:Stop() end
		if Module.MinigunEnabled then
			if HandleToFire:FindFirstChild("WindDown") then HandleToFire.WindDown:Play() end
			wait_(Module.DelayAfterFiring)
		end
		Enabled = true
		if Ammo <= 0 then Reload() end
	end
end)
Mouse.Button1Up:connect(function()
	Down = false
end)

ChangeAmmoAndClip.OnClientEvent:connect(function(ChangedAmmo,ChangedClips)
	Ammo = ChangedAmmo
	Clips = ChangedClips
	UpdateGUI()
end)
Tool.Equipped:connect(function(TempMouse)
	Equipped = true
	UpdateGUI()
	if Module.AmmoPerClip ~= math.huge then GUI.Parent = Player.PlayerGui end
	TempMouse.Icon = "rbxassetid://"..Module.MouseIconID
	if IdleAnim then IdleAnim:Play(nil,nil,Module.IdleAnimationSpeed) end
	TempMouse.KeyDown:connect(function(Key)
		if string.lower(Key) == "r" then
			Reload()
		elseif string.lower(Key) == "e" then
			Secondary = not Secondary
			if not Reloading then UpdateGUI() end
			--[[if not Reloading and AimDown == false and Module.SniperEnabled then
				workspace.CurrentCamera.FieldOfView = Module.FieldOfView
				--[[local GUI = game.Players.LocalPlayer.PlayerGui:FindFirstChild("ZoomGui") or Tool.ZoomGui:Clone()
				GUI.Parent = game.Players.LocalPlayer.PlayerGui
				GUI.Scope.Visible = true
				--game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
				script["Mouse Sensitivity"].Disabled = false
				AimDown = true
				Mouse.Icon="http://www.roblox.com/asset?id=187746799"
			else
				workspace.CurrentCamera.FieldOfView = 70
				--[[local GUI = game.Players.LocalPlayer.PlayerGui:FindFirstChild("ZoomGui")
				if GUI then GUI:Destroy() end
				GUI.Scope.Visible = false
				--game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
				script["Mouse Sensitivity"].Disabled = true
				AimDown = false
				Mouse.Icon = "rbxassetid://"..Module.MouseIconID
			end]]
		end
	end)
	if Module.DualEnabled and not workspace.FilteringEnabled then
		Handle2.CanCollide = false
		local LeftArm = Tool.Parent:FindFirstChild("Left Arm")
		local RightArm = Tool.Parent:FindFirstChild("Right Arm")
		if RightArm then
			local Grip = RightArm:WaitForChild("RightGrip",0.01)
			if Grip then
				Grip2 = Grip:Clone()
				Grip2.Name = "LeftGrip"
				Grip2.Part0 = LeftArm
				Grip2.Part1 = Handle2
				--Grip2.C1 = Grip2.C1:inverse()
				Grip2.Parent = LeftArm
			end
		end
	end
	if Humanoid.Health > 0 then
		viewmodel()
	end
	recoil.Value = false
end)
Tool.Unequipped:connect(function()
	Equipped = false
	GUI.Parent = script
	if IdleAnim then IdleAnim:Stop() end
		if AimDown then
			workspace.CurrentCamera.FieldOfView = 70
			--[[local GUI = game.Players.LocalPlayer.PlayerGui:FindFirstChild("ZoomGui")
			if GUI then GUI:Destroy() end]]
			GUI.Scope.Visible = false
			--game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
			script["Mouse Sensitivity"].Disabled = true
			AimDown = false
			Mouse.Icon = "rbxassetid://"..Module.MouseIconID
		end
	if Module.DualEnabled and not workspace.FilteringEnabled then
		Handle2.CanCollide = true
		if Grip2 then Grip2:Destroy() end
	end
	endviewmodel()
end)
Humanoid.Died:connect(function()
	Equipped = false
	GUI.Parent = script
	if IdleAnim then IdleAnim:Stop() end
		if AimDown then
			workspace.CurrentCamera.FieldOfView = 70
			--[[local GUI = game.Players.LocalPlayer.PlayerGui:FindFirstChild("ZoomGui")
			if GUI then GUI:Destroy() end]]
			GUI.Scope.Visible = false
			--game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
			script["Mouse Sensitivity"].Disabled = true
			AimDown = false
			Mouse.Icon = "rbxassetid://"..Module.MouseIconID
		end
	if Module.DualEnabled and not workspace.FilteringEnabled then
		Handle2.CanCollide = true
		if Grip2 then Grip2:Destroy() end
	end
	endviewmodel()
end)

Character.Humanoid:EquipTool(Tool)

Wow. Thats lots of lines of code. However, I would recommend making the script INSIDE the viewmodel, then use models instead of tools to equip stuff. For example, in my game, I have a folder called “Current” and I put the tool that wants to be equipped in that folder. I then weld it to the character.

Inside of the viewmodel script, I play the animation for the viewmodel whenever clicked, then I play the same animation on the character.

I would recommend making a folder called “Animations” inside of the viewmodel, and inside that folder, make two folders that are labeled “ViewmodelAnimations” and “PlayerAnimations”.

Its self explanatory from there. Whenever you play an animation for the viewmodel, play the animation for the player too.

(Also, putting the viewmodel in CurrentCamera is bad practice. just add a folder called “ViewmodelClient” and put it in there.)

3 Likes

Sure, i may improve all of this stuff and probably quit using the Camera to put the viewmodels in. However, i found a solution, which is what you said, script the animations on the viewmodel, which worked after i made some bool values that trigger them.

1 Like

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