Attempt to index nil error

“Players.mw3ak471230.PlayerScripts.CoreClient:58: attempt to index nil with ‘Deactivate’ - Players.mw3ak471230.PlayerScripts.CoreClient, line 58 - function GetHumanoid
Players.mw3ak471230.PlayerScripts.CoreClient, line 165”

local function GetHumanoid(char)
	if char then
		Services.DynamicArms.Deactivate()
		Services.InteractController.Init()
		Services.Verificator.Init()
		humanoid = char:WaitForChild("Humanoid")
		Services.MovementController.OnDeath()
		Services.MovementController.InitHumanoid(humanoid)
		SetupDefaults(humanoid)
		Services.JusticeController.InitHumanoid(humanoid)
		Services.KeyBinder.InitHumanoid(humanoid)
		Services.InventoryController.InitHumanoid(humanoid)
		Services.VehicleController.InitHumanoid(humanoid, playerGui)
	    Services.Minimap.InitHumanoid(humanoid)
		Services.BankController.InitHumanoid(humanoid)
		Services.ClientFunctions.InitHumanoid(humanoid)
		Services.RadioController.Init(playerGui, humanoid)
		--Services.JusticeController.CheckJail(humanoid, playerGui)
		Services.ToolHandler.Init(humanoid)
		Services.DynamicArms.Init(humanoid)
		if not loaded then
			loaded = true
			do
				local cmdr = require(ReplicatedStorage:WaitForChild("Resources").Libraries:WaitForChild("CmdrClient"))
				local roles = Services.Verificator.GetPlayerRoles()
				cmdr:SetEnabled(roles.Moderator or roles.Admin or false)
				cmdr:SetActivationKeys({
					Enum.KeyCode.Semicolon
				})
				screen:End()
				local hotkeyEnabled = false
				local currentState = true
				local hideNames = false
				local lastHit = tick()
				local Assets = require(ReplicatedStorage.Databases.Assets)
				local chars = {}
				local function PlayerAdded(argPlayer)
					local function CharAdded(argChar)
						local hum = argChar:WaitForChild("Humanoid")
						hum.DisplayDistanceType = not (not currentState and hideNames) and Enum.HumanoidDisplayDistanceType.Viewer or Enum.HumanoidDisplayDistanceType.None
						chars[argPlayer] = hum
					end
					argPlayer.CharacterAdded:Connect(CharAdded)
					if argPlayer.Character then
						CharAdded(argPlayer.Character)
					end
				end
				Players.PlayerAdded:Connect(PlayerAdded)
				Players.PlayerRemoving:Connect(function(plr)
					chars[plr] = nil
				end)
				for _, v in pairs(Players:GetPlayers()) do
					PlayerAdded(v)
				end
				local guis = {}
				local function ChildAdded(child)
					if child:IsA("LayerCollector") then
						guis[child] = true
						child.Enabled = currentState
					end
				end
				playerGui.ChildAdded:Connect(ChildAdded)
				playerGui.ChildRemoved:Connect(function(child)
					guis[child] = nil
				end)
				for _, v in pairs(playerGui:GetChildren()) do
					ChildAdded(v)
				end
				UserInputService.InputBegan:Connect(function(inputObject, processed)
					if processed or not hotkeyEnabled then
						return
					end
					if inputObject.KeyCode == Enum.KeyCode.Backquote then
						local thisHit = tick()
						if thisHit - lastHit <= 0.5 then
							currentState = not currentState
							local ctrlDown = UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) or UserInputService:IsKeyDown(Enum.KeyCode.RightControl)
							local shiftDown = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) or UserInputService:IsKeyDown(Enum.KeyCode.RightShift)
							for gui, _ in pairs(guis) do
								gui.Enabled = currentState
							end
							if player.Character then
								for _, v in pairs(player.Character:GetDescendants()) do
									if v:IsA("BasePart") or v:IsA("Decal") then
										v.LocalTransparencyModifier = not (not currentState and ctrlDown) and 0 or 1
									end
								end
							end
							mouse.Icon = currentState and "" or Assets.Blank
							hideNames = shiftDown
							for _, v in pairs(chars) do
								v.DisplayDistanceType = not (not currentState and hideNames) and Enum.HumanoidDisplayDistanceType.Viewer or Enum.HumanoidDisplayDistanceType.None
							end
						end
						lastHit = tick()
					end
				end)
				local function CheckHideGuis()
					local roles = Services.Verificator.GetPlayerRoles()
					hotkeyEnabled = roles.PBSTeam
				end
				CheckHideGuis()
				Services.Verificator.OnVerifyUpdate:Connect(CheckHideGuis)
			end
		end
	end
end

wait(0.5)
GetHumanoid(player.Character)
player.CharacterAdded:Connect(GetHumanoid)

Services.DynamicArms does not contain a function called Deactivate

Should I try removing Deactivate?

I have no idea how your code works I’m simply pointing out what the error you’re receiving means.

well i know what it means, im trying to fix it

Then you have to provide the code for Services.DynamicArms

I have a module for DynamicArms under the main cloreclient script

local API = {}
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local RemoteHandler = require(script.Parent.RemoteHandler)
local BIND_NAME = "DynamicArms"
local LEFT_C0, RIGHT_C0, NECK_C0
local updateYRemote = RemoteHandler.Event.new("YUpdate")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local aimPart, camera
local aimEndEvent = Instance.new("BindableEvent")
local aiming = false
local RANDOM, RAD, RAY, V3, CF, CFANG = math.random, math.rad, Ray.new, Vector3.new, CFrame.new, CFrame.Angles
local BC, INST, COLSEQ, FORMAT, INSERT = BrickColor.new, Instance.new, ColorSequence.new, string.format, table.insert
local FLOOR = math.floor
local function UpdateThirdPerson(char, vectorY, vectorX)
	if not (char and vectorY) or not vectorX then
		return
	end
	local leftShoulder, rightShoulder, neck
	local suc, err = pcall(function()
		leftShoulder = char.Humanoid.RigType == Enum.HumanoidRigType.R6 and char.Torso["Left Shoulder"] or char.LeftUpperArm.LeftShoulder
		rightShoulder = char.Humanoid.RigType == Enum.HumanoidRigType.R6 and char.Torso["Right Shoulder"] or char.RightUpperArm.RightShoulder
		neck = char.Humanoid.RigType == Enum.HumanoidRigType.R6 and char.Torso.Neck or char.Head.Neck
	end)
	if suc and LEFT_C0 and RIGHT_C0 and NECK_C0 then
		if char.Humanoid.RigType == Enum.HumanoidRigType.R6 then
			leftShoulder.C0 = LEFT_C0 * CFANG(0, 0, -vectorY)
			rightShoulder.C0 = RIGHT_C0 * CFANG(0, 0, vectorY)
			if neck then
				neck.C0 = NECK_C0 * CFANG(-vectorY, 0, -vectorX)
			end
		else
			leftShoulder.C0 = LEFT_C0 * CFANG(vectorY, 0, 0)
			rightShoulder.C0 = RIGHT_C0 * CFANG(vectorY, 0, 0)
			if neck then
				neck.C0 = NECK_C0 * CFANG(vectorY, 0, 0)
			end
		end
	end
end
updateYRemote.OnEvent:Connect(UpdateThirdPerson)
function API.Init(humanoid)
	local character = humanoid.Parent
	local findFirstClass = character.FindFirstChildOfClass
	camera = workspace.CurrentCamera
	local leftShoulder = character.Humanoid.RigType == Enum.HumanoidRigType.R6 and character.Torso["Left Shoulder"] or character.LeftUpperArm.LeftShoulder
	local rightShoulder = character.Humanoid.RigType == Enum.HumanoidRigType.R6 and character.Torso["Right Shoulder"] or character.RightUpperArm.RightShoulder
	local neck = character.Humanoid.RigType == Enum.HumanoidRigType.R6 and character.Torso.Neck or character.Head.Neck
	LEFT_C0 = leftShoulder.C0
	RIGHT_C0 = rightShoulder.C0
	NECK_C0 = neck.C0
	local torso = character.Humanoid.RigType == Enum.HumanoidRigType.R6 and character.Torso or character.UpperTorso
	local rootPart = character.HumanoidRootPart
	local lastUpdate = tick()
	local lastX = FLOOR(-camera.CFrame:toObjectSpace(rootPart.CFrame).lookVector.x / 0.1) * 0.1
	local lastY = FLOOR(camera.CFrame.lookVector.y / 0.1) * 0.1
	local tweenStart = tick()
	RunService:BindToRenderStep(BIND_NAME, Enum.RenderPriority.Camera.Value + 1, function()
		local vectorX = -camera.CFrame:toObjectSpace(rootPart.CFrame).lookVector.x
		local vectorY
		if findFirstClass(character, "Configuration") then
			vectorY = mouse.Origin.lookVector.y
		else
			vectorY = camera.CFrame.lookVector.y / 2
		end
		local flooredY = FLOOR(vectorY / 0.1) * 0.1
		local flooredX = FLOOR(vectorX / 0.1) * 0.1
		local now = tick()
		if (lastY ~= flooredY or lastX ~= flooredX) and now - lastUpdate > 0.2 then
			lastUpdate = now
			lastY = flooredY
			lastX = flooredX
			updateYRemote:Fire(vectorY, vectorX)
		end
		if (camera.Focus.p - camera.CFrame.p).Magnitude <= 0.9 then
			local cameraOffset = CF(0, 1.5, 0) * CF(humanoid.CameraOffset)
			if aimPart and aimPart.Parent then
				if not aiming then
					tweenStart = tick()
				end
				aiming = true
				local oldLC0 = leftShoulder.C0
				local oldRC0 = rightShoulder.C0
				leftShoulder.C0 = LEFT_C0
				rightShoulder.C0 = RIGHT_C0
				local torsoOffset = torso.CFrame:toObjectSpace(rootPart.CFrame)
				local aimOffset = aimPart.CFrame:toObjectSpace(cameraOffset * torso.CFrame)
				local rotAim = cameraOffset * torsoOffset * CFANG(vectorY, 0, 0) * cameraOffset:inverse() * aimOffset
				leftShoulder.C0 = oldLC0
				rightShoulder.C0 = oldRC0
				local delta = (tick() - tweenStart) / 0.15
				if delta > 1 then
					delta = 1
				end
				leftShoulder.C0 = leftShoulder.C0:lerp(rotAim * LEFT_C0, delta)
				rightShoulder.C0 = rightShoulder.C0:lerp(rotAim * RIGHT_C0, delta)
			else
				if aiming then
					tweenStart = tick()
				end
				aiming = false
				local rotWithCam = cameraOffset * CFANG(vectorY, 0, 0) * cameraOffset:inverse()
				if character.Humanoid.RigType == Enum.HumanoidRigType.R6 then
					local delta = (tick() - tweenStart) / 0.25
					if delta > 1 then
						delta = 1
					end
					leftShoulder.C0 = leftShoulder.C0:lerp(rotWithCam * LEFT_C0, delta)
					rightShoulder.C0 = rightShoulder.C0:lerp(rotWithCam * RIGHT_C0, delta)
				else
					leftShoulder.C0 = rotWithCam * LEFT_C0
					rightShoulder.C0 = rotWithCam * RIGHT_C0
				end
			end
		else
			if aiming then
				aiming = false
				aimEndEvent:Fire()
			end
			UpdateThirdPerson(character, vectorY, vectorX)
		end
	end)
	humanoid.Died:Connect(function()
		API.Deactivate()
	end)
end
function API.SetAimPart(argAim)
	aimPart = argAim
end
function API.CanAim()
	return (camera.Focus.p - camera.CFrame.p).Magnitude < 1
end
function API.GetAimPart()
	return aimPart
end
function API.GetEndAimEvent()
	return aimEndEvent.Event
end
function API.Deactivate()
	RunService:UnbindFromRenderStep(BIND_NAME)
end
return API

Can you show the code where you actually define Services.DynamicArms? The module itself doesn’t seem to contain the problem so it’s probably wherever you define it.

its defined in the code above, on the coreclient script, thats the only place its defined at

local function GetHumanoid(char) at line 1

is getting a index nil error to line 58

Services.DynamicArms.Init(humanoid)

No you showed the code for the DynamicArms module and for the function that was erroring but within the function that was erroring you’re calling Services.DynamicArms.Deactivate(). Where do you define the Services variable and the Services.DynamicArms variable?

The service is defined to a module

Your error message means that Services.DynamicArms is nil (so Services doesn’t have a property called DynamicArms). Your code is basically trying to run nil.Deactivate().

@AstrealDev is asking where the .DynamicArms property of the Services module is set. You can find this by searching “.DynamicArms” in the Services module.

The problem probably is that your module doesn’t have a line of code that looks something like this:

Services.DynamicArms = require(module) -- module is the DynamicArms module
2 Likes

Actually, it means that Services.DynamicArms is nil.

1 Like

Yeah I realized that once I saw the module’s code which is why I was asking for where the variable Services.DynamicArms is defined.