I am trying to animate a viewmodel that I have updating to the camera position. I am trying to use a humanoid inside of the viewmodel I am referencing in my script. As I try to load the animation onto the humanoid inside of the viewmodel, it gives me this error: ServerScriptService.loadAnimation:19: attempt to index nil with 'Humanoid'

Scripts:

ServerScript (in serverscriptservice): game.ReplicatedStorage.Events.playAnimation.OnServerEvent:Connect(function(player, id, loop, vmName) print("attempt to play animation") if not loop then -- Checks if I want the animation to loop, such as for a holding animation local animation = Instance.new("Animation") animation.AnimationId = "rbxassetid://"..id local loadedAnimation = vmName.Humanoid:LoadAnimation(animation) --local loadedAnimation = game.Workspace[player.Name][vmName]:FindFirstChildWhichIsA("Humanoid"):LoadAnimation(animation) loadedAnimation:Play() loadedAnimation.Stopped:Wait() game.ReplicatedStorage.animationDone:FireClient()

	loadedAnimation:Destroy() -- Asset Cleanup
	animation:Destroy() 
else
	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://"..id
	local loadedAnimation = vmName.Humanoid:LoadAnimation(animation)
	--local loadedAnimation = game.Workspace[player.Name][vmName]:FindFirstChildWhichIsA("Humanoid"):LoadAnimation(animation)
	local brek = false -- had to name this brek because break was already associated with break
	loadedAnimation:Play()
	print(loadedAnimation.isPlaying)
	game.ReplicatedStorage.Events.unLoop.OnServerEvent:Connect(function(plr) -- for when I want to terminate the loop
		if plr == player then
			loadedAnimation:Stop()
			loadedAnimation:Destroy() -- Asset Cleanup
			animation:Destroy()
		end
	end)
end

end)

localscript (in starterplayerscripts): local player = game.Players.LocalPlayer local mouse = player:GetMouse() local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("VM1911").Humanoid local run = game:GetService("RunService") -- basics local vm = game.ReplicatedFirst.VM1911 local modelName = game.Workspace[player.Name]:WaitForChild("VM1911") print(modelName.Name) local name = "1911 Tactical"

-- set animations local animations = {} animations["reload"] = "6283824322" animations["hold"] = "6283828261" animations["equip"] = "6283820139" animations["fire"] = "6283836079" animations["holdempty"] = "6283832178" animations["reloadempty"] = "6283834370" -- set bullet properties local bulletNum = 1 local bulletSpread = 0 local bulletSpeed = 3000 local headDamage = 75 local torsoDamage = 50 local limbDamage = 25 local ap = 0 local silenced = false

-- other properties local fireRate = .5 local fullAuto = false local maxAmmo = 7 local slot = "secondary" local canChamber = true

local ammo = maxAmmo function stand() game.ReplicatedStorage.Events.playAnimation:FireServer(animations["hold"], true, modelName) end

function standEmpty() game.ReplicatedStorage.Events.playAnimation:FireServer(animations["holdempty"], false, modelName) end

function fire() game.ReplicatedStorage.Events.unLoop:FireServer() game.ReplicatedStorage.Events.playAnimation:FireServer(animations["fire"], false, modelName) if ammo >= 0 then standEmpty() else stand() end end wait(20) stand()

I know that there is a humanoid in the viewmodel, and have checked that it is in the player character where I put it.

1 comment

0

Messed up the formatting a bit, sorry!