.__index Not Working

I am making a tycoon game and this is a dropper script. To test it I set DropSpeed as nil so that it indexes the module’s DropSpeed(Which is the default speed that is given if no specicified one was given in the child table). For some reason it still puts DropSpeed as nil.

I checked it multiple times and I still can’t find the problem. The script is pretty simple so hopefully someone can find it. If you do find the problem, please tell me! Thanks!

Script:

local module = {--Default Data
	data = {
		DropSpeed = 5,
		Color = Color3.new(1, 0, 0),
		Material = Enum.Material.Neon,
		CashWorth = 2
	}
}

module.__index = module

module.Type1 = {--DROPSPEED TURNED TO NIL HERE
	DropSpeed = nil, --Time in between blocks drop from dropper
	Color = Color3.new(1, 0.835294, 0), --Color of block
	Material = Enum.Material.Neon, -- Material of block
	CashWorth = 1, --Amount of money block costs


}


--THIS IS WHERE "TYPE" VARIABLE IS GIVEN
function module.FindType(Model)--self = droppermodel
	if not module[Model.DropperType.Value] then return end
	return module[Model.DropperType.Value]
end







--METATABLE MADE HERE
function module.NewDropper(model, Type, Indexnum)--Type is module.Type1(Found at the top)
	local SmallTable = setmetatable({
		Model = model,
		DropSpeed = Type.DropSpeed,
		Color = Type.Color,
		Material = Type.Material,
		CashWorth = Type.CashWorth
		
		}, module)	
	
	
	return SmallTable
end



function module:Drop()
	wait(1)--Waits for dropper to appear
	while true do
		local block = Instance.new("Part")
		block.Anchored = false
		block.Size = Vector3.new(1,1,1)
		block.Name = "Block"

		block.Color = self.Color
		block.Material = self.Material
		block.Position = self.Model.DropHole.Position + Vector3.new(0, -1, 0)
		block.Parent = workspace
		game:GetService("Debris"):AddItem(block, 10)

		print(self.DropSpeed)--IT STILL IS NIL!!
		wait(self.DropSpeed)
	end
end

return module

Found it myself. Only took like 2 hours. The module had a module.data table and all the data was in there and not the actual module.

1 Like

I see you replying!!!

1 Like

No need for that though. But thanks! Lol

People might get the wrong idea (you talking to yourself), anyway, I was looking at the code for a second and I thought, “brother, wasn’t this your intention the entire time?”, but once I actually realized it, you had already replied. r.i.p.

Lol I found out the problem after I saw someone was replying for about 5 minutes, so I felt bad because they probably typed a whole 2 paragraph essay for nothing.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.