I have the following server script calling other module scripts in order to create bossfight attacks.
local nextevent = script.Parent.NextEvent
local atktable = {}
for _, v in pairs(script.Parent.Attacks:GetChildren())do
if v:IsA("Folder") and v:FindFirstChild("AttackBehaviour") then
require(v:FindFirstChild("AttackBehaviour"))
table.insert(atktable, v:FindFirstChild("AttackBehaviour"))
end
end
local function useAttack()
atktable[math.random(1, #atktable)]:startAttack()
end
useAttack()
nextevent.Event:Connect(function(param)
if param == "UseNext" then
useAttack()
end
end)
Within the AttackBehaviour modules, it looks something like this:
local module = {}
local ShootTurret = require(game.ReplicatedStorage.AttackPresets.ShootTurret)
local nextevent = script.Parent.Parent.Parent.NextEvent
function module:endAttack()
for _, v in pairs(script.Parent:GetChildren())do
if v.Name == "FireEffect" then
v:FindFirstChild("ParticleEmitter").Enabled = false
end
end
nextevent:Fire("UseNext")
end
function module:startAttack()
print("Attack2")
for _, v in pairs(script.Parent:GetChildren())do
if v.Name == "FireEffect" then
v:FindFirstChild("ParticleEmitter").Enabled = true
end
end
ShootTurret:shootBullet(script.Parent.Turret, 250, 10, 5, Color3.fromRGB(45, 144, 206), nil)
task.wait(0.5)
module:endAttack()
end
module.startAttack()
return module
The modules run succesfully (i think?) twice until it returns the error. module:startAttack()
and module.startAttack()
makes no difference