Math.Random Repeat

Im trying to make a script where an NPC fires attacks every few seconds towards a player.
The problem is that instead of doing another attack after the first it stops. Which isn’t what i want.

local Attack2 = "Flare Bomber"
local Attack3 = "Galactic Beam"
local Attack4 = "Blackhole"
local Attack5 = "Tormented Souls"
local Attack6 = "Solar Storm"
local Attack7 = "Explosive Astroid"
local TimeCooldown = math.random(5,12)
local demon = game.Workspace:FindFirstChild("Demon")

local AttackTable = {Attack1} -- ,Attack2,Attack3,Attack4,Attack5,Attack6,Attack7}
local CurrentAttack = (AttackTable[math.random(1, #AttackTable)])
print(CurrentAttack)

if CurrentAttack == "Universal Torture" then
-- The code here isn't needed

end

if CurrentAttack == "Flare Bomber" then
-- The code here isn't needed
end


The code which selects the element is at line 12

3 Likes

Have you tried using a while loop? You can use it in a coroutine if you need stuff after the loop to execute.

1 Like