Boss AI Broken?

I’m trying to make a boss fight, but it keeps throwing me this error: Workspace.???.Script:4: attempt to index nil with 'HumanoidRootPart'
Code:

while true do
	wait(0.1)
	for i,v in pairs(game.Players:GetChildren()) do
		if math.floor((v.Character.HumanoidRootPart.Position-game.Workspace["???"].HumanoidRootPart.Position).Magnitude) <= 12 then
			script.Parent.Humanoid:MoveTo(v.Character.HumanoidRootPart.Position)
		end
		if math.floor((v.Character.HumanoidRootPart.Position-game.Workspace["???"].HumanoidRootPart.Position).Magnitude) == 2 or math.floor((v.Character.HumanoidRootPart.Position-script.Parent.HumanoidRootPart.Position).Magnitude) == 1 then
		script.Play.Disabled = false
		end
	end
end

add a :WaitForChild , like so v.Character:WaitForChild("HumanoidRootPart").Position? (waitforchild is better than using . if you aren’t sure it exists)

10:09:31.830 - Workspace.???.Script:4: attempt to index nil with ‘WaitForChild’

hmm, that’s weird, are you sure their humanoidrootpart is inside that boss? im going to look into this error

It’s a normal animating rig dummy…

1 Like

are you sure that “???” even exists, your trying to waitforchild from something that dosen’t exist is what the error is saying.

1 Like

The debugger is telling you that v.Character is not existent.

You should also be using

game.Players:GetPlayers()

Your code should look like this:

while true do
	wait(0.1)
	for i,v in pairs(game.Players:GetPlayers()) do
        local character = v.Character
        
        if character then
		    if math.floor((character.HumanoidRootPart.Position-game.Workspace["???"].HumanoidRootPart.Position).Magnitude) <= 12 then
			    script.Parent.Humanoid:MoveTo(character.HumanoidRootPart.Position)
		    end
		    if math.floor((character.HumanoidRootPart.Position-game.Workspace["???"].HumanoidRootPart.Position).Magnitude) == 2 or math.floor((character.HumanoidRootPart.Position-script.Parent.HumanoidRootPart.Position).Magnitude) == 1 then
		        script.Play.Disabled = false
		    end
	    end
    end
end
1 Like