task.wait should not be called on a thread that is already ‘waiting’ in the task library
Just started one day, didn’t change anything ^^
It doesn’t break the code but I’m just confused on what this means, I tried putting wait() instead of task.wait() but it feels wrong.
--runs in a thread, a thread created for each unit in this game
local animStopped = false
local animEndConnect = attackAnimTrack.Stopped:Connect(function()
npcModule.disconnectCon(unit, "windEvent")
npcModule.setUnitStat(unit, "LastAttack", tick())
animStopped = true
end)
attackAnimTrack:Play()
repeat task.wait() until animStopped
also for this wait
task.wait(uStats.Attributes["AttackCooldown"])
Thread its running in
function npcModule.unitThread(unit) -- resumed in another loop every .1 seconds
while unit and unit:FindFirstChild("Humanoid") do
local uStats = npcModule.getUnitStats(unit)
local closestEnemy, dist = npcModule.findClosestEnemy(unit, uStats.EnemyTeam:GetChildren())
if closestEnemy then
if dist and dist < uStats.Attributes["AttackRange"] then
npcModule.setStatusAttacking(unit) -- where the error is happening
elseif unit.Humanoid.MoveDirection.Magnitude == 0 then
npcModule.setStatusMoving(unit)
end
end
coroutine.yield()
end
end
function npcModule.setStatusAttacking(unit)
npcModule.stopMove(unit)
local uStats = npcModule.getUnitStats(unit)
if tick() - uStats.LastAttack >= uStats.Attributes["AttackCooldown"] then
local canAttack = false
repeat
if tick() - uStats.LastAttack >= uStats.Attributes["AttackCooldown"] then
npcModule.Attack(unit) -- gives warning when waiting for anim to end
end
canAttack = false
local closestEnemy, dist = npcModule.findClosestEnemy(unit, uStats.EnemyTeam:GetChildren())
if closestEnemy then
if dist and dist < uStats.Attributes["AttackRange"] then
canAttack = true
task.wait(uStats.Attributes["AttackCooldown"]) --the other warning
end
end
until not canAttack
end
end