I'm Trying To Make A Bomb Tag Minigame But I'm Getting This Error Message

ErrorMessage:

  17:38:14.711  ServerScriptService.GameManager.MinigameManager:33: invalid argument #2 to 'insert' (number expected, got nil)  -  Server - MinigameManager:33

ModuleScript:

local MinigameManager = {}

---{ModuleScripts}---

local PlayerManager = require(script.Parent.PlayerManager)

---{Functions}---

local Plrs = PlayerManager.ActivePlayers
local PlayerTable = {}
local SelectedTable = {}

---{BombTagFunction}---

local function BombTag()

	if #PlayerTable == 0 then

		for Index, Value in pairs(Plrs) do

			table.insert(PlayerTable, Value)

		end

		local HalfOfPlayers = math.floor(#PlayerTable / 2)

		for Index = HalfOfPlayers, 1, -1 do

			local RandomPlayer = PlayerTable[math.random(1, #PlayerTable)]

			table.remove(PlayerTable, table.find(PlayerTable, RandomPlayer), RandomPlayer)

			table.insert(SelectedTable, table.find(SelectedTable, RandomPlayer), RandomPlayer)

		end

	elseif #PlayerTable > 0 then

		local HalfOfPlayers = math.floor(#PlayerTable / 2)

		for Index = HalfOfPlayers, 1, -1 do

			local RandomPlayer = PlayerTable[math.random(1, #PlayerTable)]

			table.remove(PlayerTable, table.find(PlayerTable, RandomPlayer), RandomPlayer)

			table.insert(SelectedTable, table.find(SelectedTable, RandomPlayer), RandomPlayer)

		end

	end

	for Index, Value in pairs(SelectedTable) do

		local Character = Value:FindFirstChild("Character")
		local Humanoid = Character:FindFirstChild("Humanoid")

		local Bomb = Instance.new("BoolValue", Character)
		Bomb.Name = "Bomb"

	end

end

local Functions = {BombTag}
local FunctionTable = {}

function MinigameManager:StartGame()
	
	---{RandomFunctions}---

	if #FunctionTable == 0 then

		for Index, Value in pairs(Functions) do

			table.insert(FunctionTable, Value)

		end

		local Function = FunctionTable[math.random(1, #FunctionTable)]

		Function()

		table.remove(FunctionTable, table.find(FunctionTable, Function), Function)

	elseif #FunctionTable > 0 then

		local Function = FunctionTable[math.random(1, #FunctionTable)]

		Function()

		table.remove(FunctionTable, table.find(FunctionTable, Function), Function)

	end

end

function MinigameManager:EndGame()
	
	---{KillPlayersWithBomb}---

	for Index, Value in pairs(Plrs) do

		local Character = Value:FindFirstChild("Character")
		local Humanoid = Character:FindFirstChild("Humanoid")

		if Value:FindFirstChild("Bomb") then

			Humanoid.Health = 0

			table.remove(SelectedTable, Index)

		end

	end

end

return MinigameManager

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

At line 33 :

table.insert(SelectedTable, table.find(SelectedTable, RandomPlayer), RandomPlayer)

The 2nd argument of table.insert takes a value, which in this case I’m assuming is nil as you’re attempting to find the player in the selected table (same table you’re trying to insert the player in). I think what you meant to do was :

table.insert(SelectedTable, RandomPlayer, Index -- leave this out if order doesnt matter.)

My mistake, Edit : 2nd argument is a number unless there are only two so it would be

table.insert(SelectedTable, RandomPlayer)

or

table.insert(SelectedTable, Index, RandomPlayer)
1 Like

Ok I Tried That And I Got This Error Message:

  17:51:06.731  ServerScriptService.GameManager.MinigameManager:56: attempt to index nil with 'FindFirstChild'  -  Server - MinigameManager:56
1 Like

At line 56 :

local Character = Value:FindFirstChild("Character") -- 55
local Humanoid = Character:FindFirstChild("Humanoid") -- 56

In this case character is nil. Assuming that Value is a player instance, it would just be player.Character to get the character (since it is a property not a child), and to make sure we dont get any errors it’s best to do :

local Character = value.Character
if Character then
    local Humanoid = Character:FindFirstChild("Humanoid")
    if Humanoid then
        -- do stuff
    end
end
1 Like

Thanks For Helping Me! This Should Help Finish My Game Thx Again

1 Like

Hey! Don’t forget to press on solution for @kilesix aswell! he has solved an error of your script too!
If I’m wrong my bad!