Is there a way to start attacks one by one?

Hi, I am trying to make a boss fight and it works pretty well. The only problem is that I don´t know how to make each attack start one after one. When I try to do a normal loop it wont take any other attacks and there would be 10000 attacks in one second. Is there a way to make a loop wait until the local function Attack() is done? So the next random attack can start?

local bossModel = game.Workspace.FINALBOSS_Phase1
local Humanoid = bossModel.Humanoid
local attackFolder = game.Workspace.FINALBOSS_Phase1.Boss.attackFolder
local StandingAnimation = Humanoid:LoadAnimation(bossModel.Boss.attackPositions.Standing)
local bossDied = false
StandingAnimation:Play()
									
									
									
									
									
									
local function RingAttack() -- this is a attack that will make red rings appear
local anim = Humanoid:LoadAnimation(bossModel.Boss.attackPositions.redRingAnim)
StandingAnimation:Stop()
anim:Play()
wait(1.8)
bossModel.Boss.bossAttacks.GroundSmash:Play()
local ring = attackFolder.redRing
local ringClone = ring:Clone()
ringClone.Parent = game:GetService("Workspace")
wait(0.2)
ringClone.Position = bossModel.Boss.attackPositions.ringPosition.Position 
ringClone.Size = Vector3.new(10,0.2,10)

local RingInfo = TweenInfo.new(2.6,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

local Goals = {Size = Vector3.new(200,0.2,200)} -- The Ring will go upto This Size
local tween = game:GetService("TweenService"):Create(ringClone,RingInfo,Goals)
tween:Play()
StandingAnimation:Play()

tween.Completed:Connect(function()
ringClone:Destroy()
wait(0.5)
											
end)
end
									
									
									
									
									
local function Laughing()
local laugh = Humanoid:LoadAnimation(bossModel.Head.Laughing)
laugh:Play()
laugh.Stopped:Wait()
	end
local bossDied = false

if Humanoid.Health <= 0 and bossDied == false then
bossDied = true
end
										
-- how can I make a loop that waits until a attack is over and make it select annother one?
local Attacks = {"RingAttack","Laughing","","",""}
local randomAttacks = Attacks[math.random(1,#Attacks)] -- here it chooses a random attack
									
									
-- here it will check which attack it selected and then it will start it										
if randomAttacks == "RingAttack" then
	RingAttack()
end
									
if randomAttacks == "Laughing" then
Laughing()
end

does anyone know what I need to do?

1 Like

I went into your code and added a debounce after the attacks, does this work?

local bossModel = game.Workspace.FINALBOSS_Phase1
local Humanoid = bossModel.Humanoid
local attackFolder = game.Workspace.FINALBOSS_Phase1.Boss.attackFolder
local StandingAnimation = Humanoid:LoadAnimation(bossModel.Boss.attackPositions.Standing)
local bossDied = false
local debounce = true
StandingAnimation:Play()
									
									
									
									
									
									
local function RingAttack() -- this is a attack that will make red rings appear
local anim = Humanoid:LoadAnimation(bossModel.Boss.attackPositions.redRingAnim)
StandingAnimation:Stop()
anim:Play()
wait(1.8)
bossModel.Boss.bossAttacks.GroundSmash:Play()
local ring = attackFolder.redRing
local ringClone = ring:Clone()
ringClone.Parent = game:GetService("Workspace")
wait(0.2)
ringClone.Position = bossModel.Boss.attackPositions.ringPosition.Position 
ringClone.Size = Vector3.new(10,0.2,10)

local RingInfo = TweenInfo.new(2.6,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

local Goals = {Size = Vector3.new(200,0.2,200)} -- The Ring will go upto This Size
local tween = game:GetService("TweenService"):Create(ringClone,RingInfo,Goals)
tween:Play()
StandingAnimation:Play()

tween.Completed:Connect(function()
ringClone:Destroy()
wait(0.5)
											
end)
end
									
									
									
									
									
local function Laughing()
local laugh = Humanoid:LoadAnimation(bossModel.Head.Laughing)
laugh:Play()
laugh.Stopped:Wait()
	end
local bossDied = false

if Humanoid.Health <= 0 and bossDied == false then
bossDied = true
end
										
-- how can I make a loop that waits until a attack is over and make it select annother one?
local Attacks = {"RingAttack","Laughing","","",""}
local randomAttacks = Attacks[math.random(1,#Attacks)] -- here it chooses a random attack
									
									
-- here it will check which attack it selected and then it will start it										
if randomAttacks == "RingAttack" and debounce == true then
debounce = false
	RingAttack()
debounce = true
end
									
if randomAttacks == "Laughing" and debounce == true then
debounce = false
Laughing()
wait(5) -- Delay between attacks
debounce = true
end

1 Like

it seems to work but its only repeating the same attack all the time. It must repeat all the attacks

That’s because you only get the “randomAttacks” once. If you want it to be randomized every time you have to make it a function.

So replace

local Attacks = {"RingAttack","Laughing","","",""}
local randomAttacks = Attacks[math.random(1,#Attacks)]

with this:

local Attacks = {"RingAttack","Laughing"}
local randomAttacks = "Laughing" -- First attack boss does

local function randomizeAttacks()
randomAttacks = Attacks[math.random(1,#Attacks)]
end

while true do
wait(2)
randomizeAttacks()
end
1 Like

now the boss does nothing anymore, did I do it right?

local Attacks = {"RingAttack","Laughing"}
local randomAttacks = "Laughing" -- First attack boss does

local function randomizeAttacks()
randomAttacks = Attacks[math.random(1,#Attacks)]
end

while true do
wait(2)
randomizeAttacks()
end


-- here it will check which attack it selected and then it will start it										
if randomAttacks == "RingAttack" and debounce == true then
debounce = false
RingAttack()
debounce = true
end

if randomAttacks == "Laughing" and debounce == true then
debounce = false
Laughing()
wait(5) -- Delay between attacks
debounce = true
end

Oops, forgot to make that second part a function.

local Attacks = {"RingAttack","Laughing"}
local randomAttacks = "Laughing" -- First attack boss does

local function randomizeAttacks()
randomAttacks = Attacks[math.random(1,#Attacks)]
end


-- here it will check which attack it selected and then it will start it										

local function attack()

randomizeAttacks()

if randomAttacks == "RingAttack" and debounce == true then
debounce = false
RingAttack()
debounce = true
end

if randomAttacks == "Laughing" and debounce == true then
debounce = false
Laughing()
wait(5) -- Delay between attacks
debounce = true
end

else 
end

end

while true do
wait(1)
attack()
end


1 Like

Made another quick edit to that code, should be more efficient now

1 Like

oh wait I see right now that when the boss does the laugh animation first it wont do anything else, but when he does the ring attack first then it works perfectly. Maybe you can fix that too please?

Do you mean that it will only do one type of attack when laughing is the first one but will randomize when ring is the first

1 Like

no I mean when it chooses the laugh animation, somehow the laugh wont stop playing and it wont choose annother attack. But that only happens when it chooses laugh first, when it chooses the ringattack first it works perfectly.

I’m honestly not sure what’s up with that. I’d recommend making another thread so a more experienced programmer can look at that more specific error.

1 Like