Tool Viewmodel animation not working

hello im a beginner to scripting i want to make a tool viewmodel that has animation but im struggling to make it work it always saying cannot load the animationclipprovider service. this is the script:

local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Tool = script.Parent

Tool.Equipped:Connect(function()
	local shirt = player.Character.Shirt:Clone()
	local bodycolor = player.Character["Body Colors"]:Clone()
	local Viewmodel = game.ReplicatedStorage.FistModel.VM:Clone()
	
	local idle = Viewmodel.Humanoid:LoadAnimation(script.Parent.Animations.Idle)
	idle:Play()

	run = RunService.RenderStepped:Connect(function()
		Viewmodel.Primary.CFrame = Camera.CFrame
	end)
	shirt.Parent = Viewmodel
	bodycolor.Parent = Viewmodel
	Viewmodel.Parent = game.Workspace.Camera
	
end)

Tool.Unequipped:Connect(function()
	workspace.Camera.VM:Destroy()
	run:Disconnect()
end)

i tried animationcontroller too

3 Likes

I would like further information as I think the information you have provided is a bit too brief to actually help you fix this. Please could you send a screenshot of the error, send a screenshot of the viewmodel in the explorer with everything in it expanded, and tell me how your viewmodel is intended to work.

1 Like


Got you a solution.

You should be playing animations after you have parented the viewmodel not before. For Roblox, there is no point of playing an animation on something that has a parent of nil since it just wastes memory so it just throws back an error message because the parent is equal to nil. Your code should look like this:

local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Tool = script.Parent

Tool.Equipped:Connect(function()
	local shirt = player.Character.Shirt:Clone()
	local bodycolor = player.Character["Body Colors"]:Clone()
	local Viewmodel = game.ReplicatedStorage.FistModel.VM:Clone()

	run = RunService.RenderStepped:Connect(function()
		Viewmodel.Primary.CFrame = Camera.CFrame
	end)
	shirt.Parent = Viewmodel
	bodycolor.Parent = Viewmodel
	Viewmodel.Parent = game.Workspace.Camera
	
	local idle = Viewmodel.Humanoid:LoadAnimation(script.Parent.Animations.Idle)
	idle:Play()
end)

Tool.Unequipped:Connect(function()
	workspace.Camera.VM:Destroy()
	run:Disconnect()
end)

Also, I would suggest you not to the loading the animation onto the humanoid and instead loading the animation onto the animator, which should be parented to the humanoid. Humanoid:LoadAnimation() is deprecated and should not be used; instead use Humanoid.Animator:LoadAnimation(). Another suggestion is to check if the player is wearing a shirt in the first place so you can do the appropriate operations and your code doesn’t break.

1 Like

thank you for the help i did not know about it im stupid at positioning lines.

1 Like

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