Getting the error: ServerScriptService.BunnyHandler.MainBunny:28: invalid argument #1 to 'pairs' (table expected, got nil)

Hello! I am Dev_Asher and I am working on a find the markers game remake, I made a script where when the player touched a marker or in this case Bunny, it fires a remote event to the client where it will reward the player for finding the Bunny. But now when I Fire the client it gives me an error saying ServerScriptService.BunnyHandler.MainBunny:28: invalid argument #1 to ‘pairs’ (table expected, got nil) Does anyone know how to fix this?

local HTTPService = game:GetService('HttpService')

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Players = game:GetService('Players')

local BunnyFolder = workspace:WaitForChild('BunnysFolder')

local ReplicatedModules = require(ReplicatedStorage:WaitForChild('Modules'))
local RemoteModule = ReplicatedModules.RemoteService
local BunnysModule = ReplicatedModules.Bunnys

local SystemsContainer = {  }

local BunnyTouchedEvent = RemoteModule:GetRemote('BunnyTouched', 'RemoteEvent', false)

local selectedData = nil

local Module = {}

function Module:BunnyStack(BunnyID)
	return {
		ID = BunnyID,
		UUID = HTTPService:GenerateGUID(false)
	}
end

function Module:SetProperties(Parent, propertiesTable)
	for guiObjctName, labelProperties in pairs(propertiesTable) do
		local targetGuiObject = Parent:FindFirstChild(guiObjctName)
		if targetGuiObject and targetGuiObject:IsA('Frame') then
			targetGuiObject = targetGuiObject:FindFirstChild('Label')
		end
		if not targetGuiObject then
			continue
		end
		for propertyName, propertyValue in pairs(labelProperties) do
			targetGuiObject[propertyName] = propertyValue
		end
	end
end

function Module:CheckBunnyFromID(BunnyID)	
	for i, Bunny in pairs(BunnyFolder:GetChildren()) do
		if Bunny:IsA('Part') and Bunny.Parent == BunnyFolder then
			
			Bunny.Touched:Connect(function(Hit)
				local LocalPlayer = Players:GetPlayerFromCharacter(Hit.Parent)
				BunnyTouchedEvent:FireClient(LocalPlayer, Bunny)
				local Interface = LocalPlayer:WaitForChild('PlayerGui'):WaitForChild('Ui_Interface')
				local FoundBunnyUI = Interface:WaitForChild('BunnyFound')
				local LHUD = Interface:WaitForChild('LHUD')
				
				local selectedConfig = selectedData and BunnysModule:GetItemConfig(selectedData.ID)

				FoundBunnyUI.Visible = true
				LHUD.Visible = false
				FoundBunnyUI.Icon.Image = Module:SetProperties(FoundBunnyUI.Icon.Image, BunnyID)
				wait(5)
				FoundBunnyUI.Visible = false
				LHUD.Visible = true
				
				warn('Bunny Was Touched')
			end)
		else
			warn('Touched Part Not From Bunny Folder')
		end
	end
end

function Module:Init(otherSystems)

	SystemsContainer = otherSystems

end

return Module

Some value was nil when instead it expected a table. Could you show the line of code that gave the error?

Sure

for guiObjctName, labelProperties in pairs(propertiesTable) do

Since your setting the BunnyID as the table. What are you setting it to? Could you share me that piece of code that does that? Sorry for the long edit.

Yes it gives me nil, nothing else

So what do i do now? I was thinking of making them a variable.

Oh, BunnyID is supposed to be The ID of the bunny you touched here is my BunnyConfig with all the id’s


Module.Rarities = {
	{
		Text = 'Ordinary', 
		TextColor3 = Color3.new(0.603922, 0.603922, 0.603922)
	},
	{
		Text = 'Common', 
		TextColor3 = Color3.new(1, 1, 1)
	},
	{
		Text = 'Uncommon', 
		TextColor3 = Color3.new(0.333333, 0.666667, 0.498039)
	},
	{
		Text = 'Rare', 
		TextColor3 = Color3.new(0, 0.666667, 1)
	},
	{
		Text = 'Extreme', 
		TextColor3 = Color3.new(1, 0.490196, 0.490196)
	},
	{
		Text = 'Secret', 
		TextColor3 = Color3.new(1, 0, 0)
	},
}

Module.Bunnys = {

	{
		ID = 'Normal_Bunny',
		
		Icon = 'rbxassetid://9432469802',


		Display = {
						
			Rarity = Module.Rarities[1],

			Title = {

				Text = 'Normal Bunny',
				TextColor3 = Color3.new(1, 1, 1),

			},

			Description = {
				Text = 'The First Bunny Made!',
				TextColor3 = Color3.new(1, 1, 1),
			},

		},
	},

	{
		ID = 'Flower_Bunny',
		
		Icon = 'rbxassetid://9435715365',

		
		Display = {
			

			Rarity = Module.Rarities[2],

			Title = {


				Text = 'Flower Bunny',
				TextColor3 = Color3.new(0, 1, 0.498039),

			},

			Description = {
				Text = 'Hint: Roses Are Red, Violets Are Blue I Am In Here And So Should You!',
				TextColor3 = Color3.new(1, 1, 1),
			},

		},
	},
	
	{
		ID = 'Water_Bunny',
		
		Icon = 'rbxassetid://9435736637',
		
		Display = {

			Rarity = Module.Rarities[2],

			Title = {


				Text = 'Water Bunny',
				TextColor3 = Color3.new(1, 1, 1),

			},

			Description = {
				Text = 'Hint: In The Name...',
				TextColor3 = Color3.new(1, 1, 1),
			},

		},
	},
	{
		ID = 'Sandy_Bunny',
		
		Icon = 'rbxassetid://9459484279',
		
		Display = {

			Rarity = Module.Rarities[2],

			Title = {


				Text = 'Sandy Bunny',
				TextColor3 = Color3.new(1, 1, 1),

			},

			Description = {
				Text = 'Hint: Just Look Around! :)',
				TextColor3 = Color3.new(1, 1, 1),
			},

		},
	},
	{
		ID = 'Cactus_Bunny',
		
		Icon = 'rbxassetid://9459484279',
		
		Display = {
			

			Rarity = Module.Rarities[2],

			Title = {


				Text = 'Cactus Bunny',
				TextColor3 = Color3.new(1, 1, 1),

			},

			Description = {
				Text = 'Hint: Just Look Around! :)',
				TextColor3 = Color3.new(1, 1, 1),
			},

		},
	},
	{
		ID = 'Smelly_Bunny',
		
		Icon = 'rbxassetid://9459488503',
		
		Display = {

			Rarity = Module.Rarities[2],

			Title = {


				Text = 'Cactus Bunny',
				TextColor3 = Color3.new(1, 1, 1),

			},

			Description = {
				Text = 'Hint: I smell bad :)',
				TextColor3 = Color3.new(1, 1, 1),
			},

		},
	},
}

function Module:GetItemConfig(BunnyID)
	for _, itemData in ipairs(Module.Bunnys) do
		if itemData.ID == BunnyID then
			return itemData
		end
	end
	return nil
end

return Module

Are they both in separate modules?

What do you mean? is BunnyID and icon is separate Modules?

Are the two modules you just provided in separate or the same module script.

Edit: Never mind I know it is. Just tell me the value you set the module for the ids.

Oh they are seperate, One is in server script service and one is is replicated Storage

Wait which id? BunnyID or icon?

I’m assuming this is the one right?

Yes that is the one with the ids

Could you also share the script that fires all of these functions?

Sure!

local ReplicatedService = game:GetService('ReplicatedStorage')

local Players = game:GetService('Players')

local BunnyFolder = workspace:WaitForChild('BunnysFolder')

local ReplicatedModules = require(ReplicatedService:WaitForChild('Modules'))
local RemoteModule = ReplicatedModules.RemoteService
local BunnyConfig = ReplicatedModules.Bunnys


local BunnyModule = require(script:WaitForChild('MainBunny'))


local BunnyTouchedEvent = RemoteModule:GetRemote('BunnyTouched', 'RemoteEvent', false)

for i, Bunny in pairs(BunnyFolder:GetChildren()) do
	if Bunny:IsA('Part') and Bunny.Parent == BunnyFolder then
		Bunny.Touched:Connect(function(Hit)
			local LocalPlayer = Players:GetPlayerFromCharacter(Hit.Parent)
			BunnyModule:CheckBunnyFromID()
		end)
	else
		warn('Touched Part Not From Bunny Folder')
	end
end

Ah, theres your problem right there. You forgot to set the table “BunnyID” from the module script.

How do i do this? please tell me

How would you get your BunnyID? Just write the value in the () of