How to use Animator

so i have this localscript for a viewmodel i have and im hearing im using outdated, deprecated code for my animation. can someone tell me exactly how i should type it instead? its not working for me currently

local player = game.Players.LocalPlayer

local char = player.Character

local cam = workspace.Camera

local run = game:GetService("RunService")

local arms = game.ReplicatedFirst.DeagleViewModel:Clone()

local MyGun = script.Parent

local GunHandle = MyGun:WaitForChild("Handle")

arms.Parent = cam


MyGun.Equipped:Connect(function()

	local FPSARMS = game.Workspace.Camera:WaitForChild("DeagleViewModel")
	FPSARMS.LeftArm.Transparency = 0
	FPSARMS.RightArm.Transparency = 0

	GunHandle.Transparency = 1
	
	local anim = script.ShootAnim
	local Humanoid = arms.Humanoid
	local LoadAni = Humanoid:LoadAnimation(anim)
	LoadAni:Play()

	local GunModel = FPSARMS.Deagle:GetChildren()

	for i, value2 in pairs(GunModel) do

		value2.Transparency = 0


	end


end)

if MyGun.Equipped then

	arms.Parent = cam

	run.RenderStepped:Connect(function()

		arms:SetPrimaryPartCFrame(cam.CFrame * CFrame.new(0,-2,0) * CFrame.Angles(0,0,0))

	end)	
end



MyGun.Unequipped:Connect(function()

	arms.Parent = cam

	local FPSARMS = game.Workspace.Camera:WaitForChild("DeagleViewModel")
	FPSARMS.LeftArm.Transparency = 1
	FPSARMS.RightArm.Transparency = 1

	local GunModel = FPSARMS.Deagle:GetChildren()

	for i, value in pairs(GunModel) do

		value.Transparency = 1


	end






end)
1 Like

Would you like cleaner code or a fix? Also are there any errors?

i want a fix since its not animating my viewmodel. also no, there are no errors, it just doesn’t animate it

Also, generally what I use for human animations is

local anim = player.Humanoid.Animator:LoadAnimation(game.ReplicatedStorage.Animation)
anim:Play()

Do you own the animation, and is the priority set to action?

i own the animation. wdym by priority set action

Go into the animation editor, click the three dots, and go down to animation priority and set it to Action

i used blender to create the animation

Google how to convert it to roblox, and set the animation priority. If that does not work then lmk

no like i have the animation in my roblox game, with the id and whatever but i cant open it with the editor probably cause i didnt make it through there

Look up how to to get it there, it’s possible. I’ll find a link, gimme a sec

First link I found, should help. You can also google “How to set blender animation priority in roblox”

1 Like

ohh when i loaded my animation i got that button but i never pressed it

ok so it was set to action the whole time but its just not working

Use the code format I put above, and/or debug with print statements

i realized the issue isnt in the script since the animation never loaded in the first place so im remaking it

Remember to mark as solved if you found the asnwer