Expected identifier when parsing expression, got for

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make my npc be able to avoid kill bricks that are in a map.
  2. What is the issue? Include screenshots / videos if possible!
    My script wont work . And i dont know what to do
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve thought of doing it manually but each map might have a different amount of kill bricks
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
    I’m using pathfinding modifiers to do this(]beta feature). I think the reason why i get this error is because for loops dont work in tables. If someone can please give me an alternative to this or a way to fix it, i’ll appreciate it.
    this is my table:
local AgentParams= {
	AgentRadius = 2,
	AgentCanJump = true,	
	Costs = {
		for i,v in pairs(KillBrickTable) do
		 i = math.huge
		end	
	}
}

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

This is invalid syntax. I have no clue what you are trying to write.

You can’t define a for loop to be executed inside a table like the way you are doing.

Then what else can i do???

I don’t know what you are trying to write in the first place, so I can’t help you. Your code does not even look relevant to the issue you are trying to solve.

Here’s my full script

local pathfindingservice = game:GetService("PathfindingService")
local NPC = script.Parent
local KillBrickTable = {}
for i,v in pairs(NPC.Parent:GetDescendants()) do
	if v.Name == "KillBrick" then
		local Modifer = Instance.new("PathfindingModifier")
		Modifer.ModifierId = "KillBrick" .. i
		table.insert(KillBrickTable, i, v .. i)
		Modifer.Parent = v
	end
end

local AgentParams= {
	AgentRadius = 2,
	AgentCanJump = true,	
	Costs = {
		for i,v in pairs(KillBrickTable) do
		 i = math.huge
		end	
	}
}

NPC.PrimaryPart:SetNetworkOwner(nil)
local human = NPC.Humanoid
local path =  pathfindingservice:CreatePath(AgentParams)
path:ComputeAsync(NPC.HumanoidRootPart.Position, NPC.Parent.EndPart.Position)

if path.Status == Enum.PathStatus.Success then
	local nodes = path:GetWaypoints()
	for i,v in pairs(nodes) do

		if v.Action == Enum.PathWaypointAction.Jump then
			human.Jump = true
		end
		human:MoveTo(v.Position)
		human.MoveToFinished:Wait()
	end

end

What are you expecting this code to do?

I want that part to add the stuff from the killbricktable to the costs table so the NPC can avoid the killbricks in the map.

I think you can just define as:

for i,v in pairs(NPC.Parent:GetDescendants()) do
	if v.Name == "KillBrick" then
		local Modifer = Instance.new("PathfindingModifier")
		Modifer.ModifierId = "KillBrick"
		table.insert(KillBrickTable, i, v)
		Modifer.Parent = v
	end
end
	Costs = {
		KillBrick = math.huge
	}

and so every part that has a PathfindingModifier with a ModifierId of KillBrick I don’t think every part needs to have a separate ModifierId?

Im pretty sure they do need different modifier ids

Wiki does not say you need to.

But if for some reason you do:

for i, v in pairs(NPC.Parent:GetDescendants()) do
	if v.Name == "KillBrick" then
		local Modifer = Instance.new("PathfindingModifier")
		Modifer.ModifierId = "KillBrick" .. i
		Modifer.Parent = v

		table.insert(KillBrickTable, Modifier.ModifierId)
	end
end
local AgentParams = {
	AgentRadius = 2,
	AgentCanJump = true,	
	Costs = { }
}

for i, v in pairs(KillBrickTable) do
    AgentParams.Costs[v] = math.huge
end

oh i didn’t know, let me try to change the id lolololol.
Edit: I changed the ID and it’s still broken ;-;