I made some cool particle effects for the start of my boss fight, only thing is it’s a lot of repetitive code. A better way to write the code would be tables and for loops I would presume. How would you guys do it?
local initiateBossFightEvent = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("InitiateBossFightEvent")
local TS = game:GetService("TweenService")
local db = false
local particleRise = game:GetService("ReplicatedStorage"):WaitForChild("NewSounds"):WaitForChild("ParticleRise")
local soulmask1 = game.Workspace:WaitForChild("SoulMask1")
local soulmask2 = game.Workspace:WaitForChild("SoulMask2")
local soulmask3 = game.Workspace:WaitForChild("SoulMask3")
local soulmask4 = game.Workspace:WaitForChild("SoulMask4")
local soulmask5 = game.Workspace:WaitForChild("SoulMask5")
local soulmask6 = game.Workspace:WaitForChild("SoulMask6")
local soulmask7 = game.Workspace:WaitForChild("SoulMask7")
local soulmask8 = game.Workspace:WaitForChild("SoulMask8")
local soulrise1 = game.Workspace:WaitForChild("SoulRise1")
local soulrise2 = game.Workspace:WaitForChild("SoulRise2")
local soulrise3 = game.Workspace:WaitForChild("SoulRise3")
local soulrise4 = game.Workspace:WaitForChild("SoulRise4")
local soulrise5 = game.Workspace:WaitForChild("SoulRise5")
local soulrise6 = game.Workspace:WaitForChild("SoulRise6")
local soulrise7 = game.Workspace:WaitForChild("SoulRise7")
local soulrise8 = game.Workspace:WaitForChild("SoulRise8")
-- Invisible parts that contain particles, tweens created to make them rise up
local rise1 = TS:Create(soulrise1, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false), {CFrame = CFrame.new(soulrise1.Position.X, soulrise1.Position.Y + 33, soulrise1.Position.Z) * CFrame.fromOrientation(math.rad(soulrise1.Orientation.X), math.rad(soulrise1.Orientation.Y), math.rad(soulrise1.Orientation.Z))})
local rise2 = TS:Create(soulrise2, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false), {CFrame = CFrame.new(soulrise2.Position.X, soulrise2.Position.Y + 33, soulrise2.Position.Z) * CFrame.fromOrientation(math.rad(soulrise2.Orientation.X), math.rad(soulrise2.Orientation.Y), math.rad(soulrise2.Orientation.Z))})
local rise3 = TS:Create(soulrise3, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false), {CFrame = CFrame.new(soulrise3.Position.X, soulrise3.Position.Y + 33, soulrise3.Position.Z) * CFrame.fromOrientation(math.rad(soulrise3.Orientation.X), math.rad(soulrise3.Orientation.Y), math.rad(soulrise3.Orientation.Z))})
local rise4 = TS:Create(soulrise4, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false), {CFrame = CFrame.new(soulrise4.Position.X, soulrise4.Position.Y + 33, soulrise4.Position.Z) * CFrame.fromOrientation(math.rad(soulrise4.Orientation.X), math.rad(soulrise4.Orientation.Y), math.rad(soulrise4.Orientation.Z))})
local rise5 = TS:Create(soulrise5, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false), {CFrame = CFrame.new(soulrise5.Position.X, soulrise5.Position.Y + 33, soulrise5.Position.Z) * CFrame.fromOrientation(math.rad(soulrise5.Orientation.X), math.rad(soulrise5.Orientation.Y), math.rad(soulrise5.Orientation.Z))})
local rise6 = TS:Create(soulrise6, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false), {CFrame = CFrame.new(soulrise6.Position.X, soulrise6.Position.Y + 33, soulrise6.Position.Z) * CFrame.fromOrientation(math.rad(soulrise6.Orientation.X), math.rad(soulrise6.Orientation.Y), math.rad(soulrise6.Orientation.Z))})
local rise7 = TS:Create(soulrise7, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false), {CFrame = CFrame.new(soulrise7.Position.X, soulrise7.Position.Y + 33, soulrise7.Position.Z) * CFrame.fromOrientation(math.rad(soulrise7.Orientation.X), math.rad(soulrise7.Orientation.Y), math.rad(soulrise7.Orientation.Z))})
local rise8 = TS:Create(soulrise8, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false), {CFrame = CFrame.new(soulrise8.Position.X, soulrise8.Position.Y + 33, soulrise8.Position.Z) * CFrame.fromOrientation(math.rad(soulrise8.Orientation.X), math.rad(soulrise8.Orientation.Y), math.rad(soulrise8.Orientation.Z))})
local startColor = Color3.new(17/255, 17/255, 17/255)
local endColor = Color3.new(255/255, 0, 0)
local duration = 1
-- This function makes the eyes light up
local function tweenPartColor(part)
-- define the tween info
local tweenInfo = TweenInfo.new(
duration or 1, -- duration (in seconds), defaults to 1 second
Enum.EasingStyle.Quad, -- easing style
Enum.EasingDirection.Out, -- easing direction
0, -- number of times to repeat
false -- no yoyo
)
-- create the tween
local tween = game:GetService("TweenService"):Create(part, tweenInfo, {Color = endColor})
-- set the starting color
part.Color = startColor
-- start the tween
tween:Play()
end
initiateBossFightEvent.OnClientEvent:Connect(function()
if not db then
db = true
print("boss fight initiated")
task.wait(10)
-- These pairs loops enable the particles in the corresponding particle
for i, v in pairs(soulrise1:GetChildren()) do
v.Enabled = true
end
rise1:Play()
particleRise:Play()
rise1.Completed:Connect(function()
for i, v in pairs(soulrise2:GetChildren()) do
v.Enabled = true
end
rise2:Play()
particleRise:Play()
tweenPartColor(soulmask1.Eye1)
tweenPartColor(soulmask1.Eye2)
end)
rise2.Completed:Connect(function()
for i, v in pairs(soulrise3:GetChildren()) do
v.Enabled = true
end
rise3:Play()
particleRise:Play()
tweenPartColor(soulmask2.Eye1)
tweenPartColor(soulmask2.Eye2)
end)
rise3.Completed:Connect(function()
for i, v in pairs(soulrise4:GetChildren()) do
v.Enabled = true
end
rise4:Play()
particleRise:Play()
tweenPartColor(soulmask3.Eye1)
tweenPartColor(soulmask3.Eye2)
end)
rise4.Completed:Connect(function()
for i, v in pairs(soulrise5:GetChildren()) do
v.Enabled = true
end
rise5:Play()
particleRise:Play()
tweenPartColor(soulmask4.Eye1)
tweenPartColor(soulmask4.Eye2)
end)
rise5.Completed:Connect(function()
for i, v in pairs(soulrise6:GetChildren()) do
v.Enabled = true
end
rise6:Play()
particleRise:Play()
tweenPartColor(soulmask5.Eye1)
tweenPartColor(soulmask5.Eye2)
end)
rise6.Completed:Connect(function()
for i, v in pairs(soulrise7:GetChildren()) do
v.Enabled = true
end
rise7:Play()
particleRise:Play()
tweenPartColor(soulmask6.Eye1)
tweenPartColor(soulmask6.Eye2)
end)
rise7.Completed:Connect(function()
for i, v in pairs(soulrise8:GetChildren()) do
v.Enabled = true
end
rise8:Play()
particleRise:Play()
tweenPartColor(soulmask7.Eye1)
tweenPartColor(soulmask7.Eye2)
end)
rise8.Completed:Connect(function()
tweenPartColor(soulmask8.Eye1)
tweenPartColor(soulmask8.Eye2)
end)
end
end)