Hi, so i did a Super bomb survival game today, but i ran into a problem, when i am trying to do the bomb spawning logic, this error appears
ServerScriptService.MainRound:327: attempt to index nil with ‘GetBombTag’ - Server - MainRound:327
17:54:08.376 Stack Begin - Studio
17:54:08.377 Script ‘ServerScriptService.MainRound’, Line 327 - Studio - MainRound:327
17:54:08.377 Stack End - Studio
This is the part where the spawning is
local PS = game:GetService("Players")
local SV = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SetAtt = ReplicatedStorage:WaitForChild("SetAttribute")
local visualsr = ReplicatedStorage:WaitForChild("VisualsRemote")
local soundsw = workspace:WaitForChild("Sounds")
local soundsingame = soundsw:WaitForChild("In-Game")
local gamemodules = ReplicatedStorage:WaitForChild("GameModules")
local bombSpawner = gamemodules:WaitForChild("BombSpawner")
local bombfunctions = bombSpawner:WaitForChild("AssignBombFunction")
local BombTypesFolder = bombfunctions:WaitForChild("BombTypes")
spawnBombsLoop = coroutine.create(function()
while true do
task.wait(Seed:NextNumber(1, 10)*Seed:NextInteger(1, 1.5)/currentIntensity.Value + 1.35)
local getbombsmodels = bombsfolderworks:GetChildren()
local amountofmodels = #getbombsmodels
if gamestarted.Value then
if amountofmodels <= 15 then
local x = newbombspawner.Position.X
local z = newbombspawner.Position.Z
local xS = newbombspawner.Size.X/2
local zS = newbombspawner.Size.Z/2
local pos1 = math.random(x-xS, x+xS)
local pos2 = math.random(z-zS,z+zS)
local rayOrigin = Vector3.new(pos1, newbombspawner.Position.Y, pos2)
local rayDirection = Vector3.new(0, -500, 0)
local raycasParams = RaycastParams.new()
raycasParams.FilterType = Enum.RaycastFilterType.Exclude
raycasParams.FilterDescendantsInstances = {newbombspawner}
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycasParams)
if raycastResult then
local randomSelect = SearchIn(bombModels, "", true)
if randomSelect then
if randomSelect:FindFirstChild("Model") then
local ModelFolder = randomSelect:WaitForChild("Model")
if ModelFolder then
for _, models in pairs(ModelFolder:GetChildren()) do -- here i do the bomb spawning
if models:IsA("Model") then
local cloneBombModel = models:Clone()
cloneBombModel.Parent = bombsfolderworks
cloneBombModel:PivotTo(CFrame.new(raycastResult.Position + Vector3.new(0, Seed:NextNumber(50, 75), 0)))
local bombfunctions = requirebombFunctions.createbombAndAssignFunction(cloneBombModel) -- doing that
local bombModule = bombfunctions:GetBombModule()
local GetBombTagd = bombFunctions:GetBombTag()
if bombModule then
if GetBombTagd then
bombModule.new(cloneBombModel, GetBombTagd)
end
end
-- table.insert(activeBombs, bombfunctions)
end
end
end
end
end
end
else
end
else
CleanBombs()
end
And the assign bomb functions oop module :
--ndya!!!!
local system = {}
system.__index = system
local collectionService = game:GetService("CollectionService")
local BombTypesFolder = script:WaitForChild("BombTypes")
function system:GetBombModule()
print(self)
return self.bombmodule -- and here it doesn't works either
end
function system:GetBombTag()
return self.bombtagfound -- i guess here it errors?
end
function system.createbombAndAssignFunction(bomb : model | Part | MeshPart)
assert(bomb,"Argument 'bomb' is missing")
local self = setmetatable({}, system)
self.bombmodel = bomb
self.bombmodule = nil
self.bombtagfound = nil
local tags = collectionService:GetTags(self.bombmodel)
for _, tag in pairs(tags) do
if tag then
self.bombtagfound = tag
local get = system:getBombModule(tag, self.bombmodel)
if get then
local requirem = require(get)
self.bombmodule = requirem
--requirem.new(self.bombmodel, tag)
print("Module for " .. self.bombmodel.Name or self.bombmodel:GetFullName().." Required Succesfully")
else
warn("Couldn't Find a Module for .. "..self.bombmodel.Name or self.bombmodel:GetFullName())
end
--local customFunction = tagFunctions[tag]
--if customFunction then
--customFunction(self.bombmodel)
--end
else
return warn("Couldn't Find a Tag for .. "..self.bombmodel.Name or self.bombmodel:GetFullName())
end
end
return self
end
function system:assignFunction()
--local tagFunctions = {
-- classicBomb = function(object)
-- descartado Muejejee!!
--end,
--}
print("Loading")
local tags = collectionService:GetTags(self.bombmodel)
for _, tag in pairs(tags) do
if tag then
local get = system:getBombModule(tag, self.bombmodel)
if get then
local requirem = require(get)
self.bombmodule = requirem
requirem.new(self.bombmodel, tag)
print("Module for " .. self.bombmodel.Name or self.bombmodel:GetFullName().." Required Succesfully")
else
warn("Couldn't Find a Module for .. "..self.bombmodel.Name or self.bombmodel:GetFullName())
end
--local customFunction = tagFunctions[tag]
--if customFunction then
--customFunction(self.bombmodel)
--end
else
return warn("Couldn't Find a Tag for .. "..self.bombmodel.Name or self.bombmodel:GetFullName())
end
end
end
function system:getBombModule(tagname : string, object)
for _, modules in pairs(BombTypesFolder:GetChildren()) do
if modules:IsA("ModuleScript") then
if modules.Name == tagname then
return modules
end
end
end
return nil
end
return system
If someone knows what’s wrong, please tell me!