I have a settings module, and a createpart module.
The createpart module is supposed to clone the part the amount of times it says in the settings module.
For some reason when i call the createpart function it keeps erroring that the number is nil.
Any help?
createpart function module:
local module = {}
module.__index = module
function module:CreatePart(Settings,Part,Amount)
self.settings = Settings
self.part = Part
for i=1,self.Settings.Amount do
local ok = self.Part:Clone()
ok.Parent = workspace
end
end
return module
Now the cloning is nil but why? i defined those objects in this script:
local Settings = script.ok
local main = require(script.ModuleScript)
local Part = Instance.new("Part")
game.Players.PlayerAdded:Connect(function()
main:CreatePart(Settings,Part)
end)
local Settings = script.ok
local main = require(script.ModuleScript)
local Part = Instance.new("Part")
Only two matter:
The Settings variable and the Part variable.
The settings variable is defined as the settings module and the Part is defined as the part.
function module:CreatePart(Settings,Part)
self.Settings = require(script.Parent.ok)
self.part = Part
for i=1,self.Settings.Amount do
local ee = self.Part:Clone()
ee.Parent = workspace
end
end
For some reason they’re nil and i wanna know why.
I even set the arguments to these two variables.
game.Players.PlayerAdded:Connect(function()
main:CreatePart(Settings,Part) -- here
end)
Just saw the issue!
Make sure to have your capitalization correctly!
Compare your code (broken)
local module = {}
module.__index = module
function module:CreatePart(Settings,Part,Amount)
self.settings = Settings
self.part = Part
for i=1,self.Settings.Amount do
local ok = self.Part:Clone()
ok.Parent = workspace
end
end
return module
with this one (that is probably fixed)
local module = {}
module.__index = module
function module:CreatePart(Settings,Part,Amount)
self.settings = Settings
self.part = Part
for i=1,self.settings.Amount do
local ok = self.part:Clone()
ok.Parent = workspace
end
end
return module
Issue: you set
self.settings = Settings
self.part = Part
and when you referenced those two you capitalized the letter “s” in “settings” and the letter “p” in “part”.