I have been trying to make a tower battles game for days now, but there is this little error that wont go away..
The error is the title.. Here is my script, read through it and tell me if something is wrong.
local enemyai = require(game.ServerScriptService.Modules.Classes.Enemy.EnemyAi)
local source = {}
for_.n in pairs(workspace.Course.Paths:GetChildren()) do source[n.Tag.Value] = n end
source["StartingPoint"]= workspace.Course.Other.StartPath
while wait() do spawn(function() enemyai.StartEnemy(source,"Regular") wait(3) end
In your script you did
for_.n in pairs(workspace.Course.Paths:GetChildren()) do source[n.Tag.Value] = n end
You did "for _.n" instead of "for _, n"
Example :
for _, n in pairs(workspace.Course.Paths:GetChildren()) do source[n.Tag.Value] = n end
It's a syntax mistake. Putting a period instead of a comma tells Lua to check for an index in the given table, which requires an equal sign to be applied to a number before the index in the loop in a numeric for loop. For example, this is a generic for loop...
local numbers = {1, 2, 3} for _, number in pairs(numbers) do print(number) end
...but this is a numeric for loop:
local var = {number1 = 0, number2 = 0, number3 = 0} for i = 1, var.number1 do print(i) end
A comma is used in for loops to separate the two variables from each other. Using a period makes the compiler try to index the second variable.
As everyone else said:
It's a syntax mistake. Putting a period instead of a comma tells Lua to check for an index in the given table, which requires an equal sign to be applied to a number before the index in the loop in a numeric for loop. - BashCaster
And
You did "for _.n" instead of "for _, n" - voidstaronyt
But what your also forgetting is the "i" in "ipairs". The difference what it returns. "ipairs" returns index-value, while pairs returns key-value. You can read more about the difference between "ipairs" and "pairs" here which I found helpful in this explanation.
local enemyai = require(game.ServerScriptService.Modules.Classes.Enemy.EnemyAi) local source = {} for _, n in ipairs(workspace.Course.Paths:GetChildren()) do source[n.Tag.Value] = n end source["StartingPoint"] = workspace.Course.Other.StartPath spawn(function() while wait() do enemyai.StartEnemy(source,"Regular") wait(3) end end)
Also doing "while wait() do" before a spawn function is just bad practice (unless you have a really good reason for it) because its creating a new thread everytime it repeats its self, which eventually will cause performance issues.