Attempt to index nil with "Animations"

This is the script that’s erroring:

local WeaponFramework = game:GetService("ReplicatedStorage"):WaitForChild("WeaponFramework")
local WeaponsFolder = game:GetService("ReplicatedStorage"):WaitForChild("Weapons")
local WeaponModule = require(WeaponFramework.Modules.WeaponModule)
local EquipWeaponEvent = WeaponFramework.Events.EquipWeapon

local function TransferServer(Player, WeaponModel, Viewmodel) --Local script notifies this script when the player equips and stuff and this script toggles to server side things. Hard to explain sorry.
	local Character = Player.Character or Player.CharacterAdded:Wait() or workspace:FindFirstChild(Player.Name)
	local Humanoid = Character.Humanoid or Character:WaitForChild("Humanoid")
	local AnimationsFolder = WeaponModel.Animations

	local HoldingAnimationServer = AnimationsFolder:FindFirstChild("HoldingAnimationServer")
	local LoadedHoldingAnimationServer = Viewmodel.AnimationController:LoadAnimation(HoldingAnimationServer)
	
	LoadedHoldingAnimationServer:Play()
end

EquipWeaponEvent.OnServerEvent:Connect(TransferServer)

This is the local script im firing the event from:

local Player = game:GetService("Players").LocalPlayer
local mouse = Player:GetMouse()
local UIS = game:GetService("UserInputService")

local WeaponFramework = game:GetService("ReplicatedStorage"):WaitForChild("WeaponFramework")
local WeaponsFolder = game:GetService("ReplicatedStorage"):WaitForChild("Weapons")
local EquipWeaponEvent = WeaponFramework.Events.EquipWeapon

local WeaponModule = require(WeaponFramework.Modules.WeaponModule)

local VM = WeaponFramework.Viewmodel

local ClickedKeyBind = false
local Equipped = false

local Slot = 0

--Scroll wheel weapons
local SWWeapons = {
	
	[Enum.KeyCode.One] = "FlashLight",
	[Enum.KeyCode.Two] = "Pistol"
	
}

--Keybind weapons
local KBWeapons = {
	
	[Enum.KeyCode.One] = "One",
	[Enum.KeyCode.Two] = "Two"
	
}

local function KeyBindEquip(input, gp)
	if not gp then
		if KBWeapons[input.KeyCode] then
			local ChosenWeapon = SWWeapons[input.KeyCode]			
			local CurrentWeapon = WeaponsFolder[ChosenWeapon]
			
			if CurrentWeapon then
				if ClickedKeyBind == false then
					ClickedKeyBind = true
					
					local ClonedVM = VM:Clone()
					local ClonedWN = CurrentWeapon:Clone()
					
					local AnimFolder = ClonedWN.Animations
					
					local WeaponHoldAnimClient = AnimFolder.HoldingAnimationClient
					
					WeaponModule.EnableViewmodel(ClonedVM)
					WeaponModule.Equip(ClonedWN, ClonedVM, WeaponHoldAnimClient)
					WeaponModule.Weld(ClonedWN)
					
					Equipped = true
					
					EquipWeaponEvent:FireServer(ClonedWN, ClonedVM)
					UpdaterFunction = game:GetService("RunService").RenderStepped:Connect(function(dt) --This is ugly
						WeaponModule.UpdateViewmodel(ClonedVM, dt)
					end)
				else
					ClickedKeyBind = false
					Equipped = false
					UpdaterFunction:Disconnect()
					WeaponModule.DisableViewmodel()
				end
			end
		end
	end
end

UIS.InputBegan:Connect(KeyBindEquip)

Im making an FPS framework and trinyg to handle the more basic stuff on 2 scripts

Cheers!

Based on the error, it seems like WeaponModel passed into the TransferServer function over the event doesn’t exist (is nil), so it tries to index nil with “Animations”, resulting in your error. Do you have any idea why your WeaponModel argument could be nil?

1 Like

No idea,

On the server script it says the both the viewmodel and weapon are “nil”

1 Like

Seems like you’re trying to pass a cloned object through an event. Could you perhaps try passing in the path to that object in the workspace, and then cloning it within the function on the server?

1 Like

Tried that, didn’t work at all.

are there any error messages in the console?

why are you using waitforchild this often, it is mostly used in the workspace?

why do you have triple or maybe that is the problem and why do you need it?

why don’t you store the animation id in a module script?