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