Help with Finding the position of a R6 Character's Torso

Hello, I am attempting to find the Position of a R6 Character’s Torso Part, and I get the error: “Attempt to index Nil with ‘Torso’.” I feel like I’m missing something huge here, But can’t figure it out. Here is My Code (Below)

--// Variables Pt.1
local hum = script.Parent.Humanoid
local myTorso = script.Parent.LowerTorso
local myRoot = script.Parent.HumanoidRootPart

--// Variables Pt.2
local char

--// Code

local players = game:GetService("Players")
players.PlayerAdded:Connect(function(plr)
	char = plr.Character or plr.CharacterAdded:Wait()
end)

function avoid()
	hum:MoveTo(Vector3.new(0,0,math.random(-10,10)))
	hum.MoveToFinished:Connect(function (look)
		myRoot.CFrame = CFrame.lookAt(Vector3(char.Torso.Position.X, char.Torso.Position.Y, char.Torso.Position.Z)) --Error Occurs on this line, At the "char.Torso Parts."
	end)
end

pcall(avoid)

I’ve been looking at countless DevForum post’s for about 2 hours, Doing TONS of Trial and error. All of them relate to this topic, But I’m always getting the before mentioned error. I can provide more details if need be.

Sincerely,
InfernalProgrammer

r6 Characters dont have a lowerTorso. Only Torso works. also add in a WaitForChild. Ur code should look something like this

local plr = game.players.LocalPlayer
local chr = plr.Character or pl.CharacterAdded:Wait()
local tor = Character:WaitForChild("Torso")
1 Like

Hello, In the Variables Pt.1 area, Those variables are for the Boss (Which is R15). Sorry for the confusion.

You should add in a WaitForChild I suppose

I’ll try and test it. I’ll let you know the results.

Also dont add the boss’s script in the boss itself, add it in ServerScriptStorage

Ah, Ok. Thanks for the heads up.

what were u trying to make here

Hello,
The first function (The Avoid one) is essentially part of the Boss’s A.I.
The 2nd one will be the VulnerableAttack Function,
The 3rd will LungeAttack,
4th will be LungeAttack02,
and the last one(s) will be the Stage transitions.
This will be controlled by a differention function which will be the “Brain” of the AI, using math.random to decide what to do.

I am getting the same error as before, even with wait for Child. (Updated Script)

--// Variables Pt.1
local hum = game.Workspace.Boss.Humanoid
local myTorso = game.Workspace.Boss.LowerTorso
local myRoot = game.Workspace.Boss.HumanoidRootPart

--// Variables Pt.2
local char

--// Code

local players = game:GetService("Players")
players.PlayerAdded:Connect(function(plr)
	char = plr.Character or plr.CharacterAdded:Wait()
end)

function avoid()
	hum:MoveTo(Vector3.new(0,0,math.random(-10,10)))
	hum.MoveToFinished:Connect(function (look)
		myRoot.CFrame = CFrame.lookAt(Vector3.new(char:WaitForChild("Torso").Position.X, char:WaitForChild("Torso").Position.Y, char:WaitForChild("Torso").Position.Z)) --Error Occurs on this line, At the "char:WaitForChild("Torso").Position" Parts
	end)
end

pcall(avoid)

The error is: “Attempt to Index nil with ‘WaitForChild’”
and No, Im hitting “Play” and Not “Run”. Just wanted to state this,

local Boss = game.Workspace:WaitForChild("Boss")
local hum = boss:WaitForChild("Humanoid")
local myTorso = Boss:WaitForChild("LowerTorso")
local myRoot = Boss:WaitForChild("HumanoidRootPart")

Also Can you show me a pic of your explorer?

Here you go.
Also I will send a Picture of the output when Im in.

You might be calling the Avoid() function before the character is loaded, hence its saying you are indexing nil (char) with WaitForChild.

Alrighty, Thanks, Lemme try that real quick.

Still not Working. Same Error as Before
(“Attempt to index Nil with ‘Torso’”)
Script:

--// Variables Pt.1
local hum = game.Workspace.Boss.Humanoid
local myTorso = game.Workspace.Boss.LowerTorso
local myRoot = game.Workspace.Boss.HumanoidRootPart

--// Variables Pt.2
local char

--// Code
wait(2)
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(plr)
	char = plr.Character or plr.CharacterAdded:Wait()
end)

function avoid()
	hum:MoveTo(Vector3.new(0,0,math.random(-10,10)))
	hum.MoveToFinished:Connect(function (look)
		myRoot.CFrame = CFrame.lookAt(Vector3.new(char.Torso.Position.X, char.Torso.Position.Y, char.Torso.Position.Z)) --Error Occurs on this line, At the "char:WaitForChild("Torso").Position" Parts
	end)
end
wait(2)
pcall(avoid)

The boss moves anywhere in between -10 and 10 studs, then when the Boss finished moving, The error popped up. I also tried it with “WaitForChild” But got the same error.
(“Attempt to index Nil with ‘WaitForChild’”)

What line does it says you are trying to index nil with torso

This line here. AKA Line 20. I am also Currently Debugging it by testing it with Other parts.

I figured out the problem via. Debugging already.
Code:

local Boss = game.Workspace.Boss
local BossHum = Boss:WaitForChild("Humanoid")
local BossRoot = Boss:WaitForChild("HumanoidRootPart")

local character
local players = game:GetService("Players")

wait(3)
game.Players.PlayerAdded:Connect(function (plr)
	character = plr.Character or plr.CharacterAdded:Wait()
end)

print(character) --Debug

When it prints, it says “nil”. Hope this helps.

remove the “wait(2)” above the “local players = game:GetService(“Players”)”. See if it works better.

sorry, you posted this while I was typing my previous message, remove the wait thats before the game.Players.PlayerAdded function