Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Not getting points argument after putting 2 if statements?

local finish
local character = workspace:WaitForChild("Monster")
local humanoid = character.Humanoid
local service = game:GetService("PathfindingService")

local temp

local path
local points

if finish ~= nil then
	 path = service:FindPathAsync(character.Torso.Position,finish)
	 points = path:GetWaypoints()
	temp = true
else
		wait()
end



function gethumanoids()
	local humanoidpos = {}
	
	for i,v in pairs(workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") ~= script.Parent then
			table.insert(humanoidpos,(humanoid - v.HumanoidRootPart.Position.Magnitude ))
		end
	end
	
	table.sort(humanoidpos)
	
	for i,v in pairs(humanoidpos) do
		if v ~= 1 then
			table.remove(humanoidpos.i)
		end
	end
	
	for i,v in pairs(workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") and v ~= script.Parent then
			if (script.Parent.HumanoidRootPart.Position - v.HumanoidRootPart.Position.Magnitude) == humanoidpos[1] then
				if humanoidpos[1] ~= nil then
					finish = v.HumanoidRootPart.Position
				end
			end
		end
	end
end

if temp ~= false then
	for i,v in pairs(points) do
		wait(.2)
		gethumanoids()
		local part = Instance.new("Part", workspace)
		part.Size = Vector3.new(1,0.5,1)
		part.Anchored = true
		part.Name = "Stud"
		part.CanCollide = false
		part.Position = v.Position
	
		humanoid.WalkToPoint = part.Position
	
	end
end

Workspace.Script:50: bad argument #1 (table expected, got nil)

The above error given from the output is in line 50, the points is nil for some reason even if i made 2 solutions to that. Any solutions?

4 comments

0

The following script is to make the "monster" target the nearest player.

0

where are you using points??? All I see is “local points”

0

Do view all 63 lines

0

You never set the value of local points though because you just do if finish ~= nil then else wait() end and then it continues on the script until the bottom and errors

1 answer

I think the problem is this right here.


if finish ~= nil then
     path = service:FindPathAsync(character.Torso.Position,finish)
     points = path:GetWaypoints()
    temp = true
else
        wait()
end

You only set points once and it remains nil because the if statement doesn't pass at the time, you have to loop it or set it again.

Maybe try setting the points inside of the function itself?

2 comments

0

I'll try this.

0

Still getting the same issue.

This discussion is preserved as it was. New answers, comments, and votes are closed.