Module script 2nd function is not firing?

so im trying to create a tree growing system and i made a module script responsible for growing functions. so the first function is working fine, but the second one is not firing at all.

local module = {}

module.plantSadzonka = function(nazwadrzewa,nazwabiomu,pozycja,wybranyPart)
	local regionTreeModel = workspace:FindFirstChild("TreeRegion_"..nazwabiomu)
	local moduledrzewa = require(game.ServerScriptService.Drzewa.RodzajeDrzew:FindFirstChild(nazwadrzewa))
	local sadzonkaModel = Instance.new("Model",regionTreeModel)
	sadzonkaModel.Name = "Drzewo"
	local sadzonka = Instance.new("Part",sadzonkaModel)
	sadzonka.Name = "Drewno"
	sadzonka.Anchored = true
	sadzonka.BrickColor = moduledrzewa.kolory.kora
	sadzonka.Material = moduledrzewa.material.kora
	local treeClass = Instance.new("StringValue",sadzonkaModel)
	treeClass.Name = "RodzajDrzewa"
	treeClass.Value = nazwadrzewa
	sadzonka.Orientation = Vector3.new(math.random(moduledrzewa.katsadzonki.minimalny,moduledrzewa.katsadzonki.maksymalny),math.random(moduledrzewa.katsadzonki.minimalny,moduledrzewa.katsadzonki.maksymalny),math.random(moduledrzewa.katsadzonki.minimalny,moduledrzewa.katsadzonki.maksymalny))
	sadzonka.Size = Vector3.new(moduledrzewa.sadzonkaWielkosc.grubosc,moduledrzewa.sadzonkaWielkosc.wysokosc,moduledrzewa.sadzonkaWielkosc.grubosc)
	sadzonka.Position = wybranyPart.Position + pozycja
end

module.rosniecieLoop = function(sadzonka,rodzajdrzewa,growspeed)
	local moduledrzewa = require(game.ServerScriptService.Drzewa.RodzajeDrzew:FindFirstChild(rodzajdrzewa))
	while true do
		wait(math.random(moduledrzewa.odstepmiedzywzrostami.minimalny,moduledrzewa.odstepmiedzywzrostami.maksymalny)/growspeed)
		sadzonka.Size = sadzonka.Size + Vector3.new(moduledrzewa.wzrostsadzonki.grubosc,moduledrzewa.wzrostsadzonki.wysokosc,moduledrzewa.wzrostsadzonki.grubosc)
	end
end

return module

its in polish so you may not understand but it doesnt matter, because the problem is that the second function doenst fire at all. i tried putting a print() on the beginning and it didnt print. any help appreciated i couldnt find anything on the internet.

heres the script that fires the function (the not working function is on the bottom):

local regionTreeModel = Instance.new("Model",workspace)
regionTreeModel.Name = "TreeRegion_Test"
local nazwabiomu = "Test"
--drzewka
local drzewo1 = "Test"
local drzewo1module = require(game.ServerScriptService.Drzewa.RodzajeDrzew:FindFirstChild(drzewo1))
rzadkosc1 = 100
--koniec drzewek

local growingmodule = require(game.ServerScriptService.Drzewa.Rosniecie)
local region = workspace.Regiony.Region_Test
local growParts = {}
local limitdrzew = 25
local growspeed = 1 -- im wiekszy tym mniejsze odstepy pomiedzy wzrostami
local growdelay = 0.5 -- im wiecej tym wolniej beda sie pojawiac sadzonki
local growrate = 5 -- im wiecej tym mniejsze szanse na to ze urosnie (nie dawac przecinka)

repeat
	wait(growdelay)
	if math.random(1,growrate) == 1 then
		for i,v in pairs(region:GetDescendants()) do
			if v.Name == "Ziemia" then
				table.insert(growParts,v)
			end
		end
		local growablePart = growParts[math.random(1,#growParts)]
		local pozycja = Vector3.new(math.random(-growablePart.Size.X/2,growablePart.Size.X/2),growablePart.Size.Y/2,math.random(-growablePart.Size.Z/2,growablePart.Size.Z/2))
		growingmodule.plantSadzonka(drzewo1,"Test",pozycja,growablePart)
	end
until #regionTreeModel:GetChildren() >= limitdrzew

regionTreeModel.ChildRemoved:Connect(function()
	repeat
		if #regionTreeModel:GetChildren() < limitdrzew then
			wait(growdelay)
			if math.random(1,growrate) == 1 then
				for i,v in pairs(region:GetDescendants()) do
					if v.Name == "Ziemia" then
						table.insert(growParts,v)
					end
				end
				local growablePart = growParts[math.random(1,#growParts)]
				local pozycja = Vector3.new(math.random(-growablePart.Size.X/2,growablePart.Size.X/2),growablePart.Size.Y/2,math.random(-growablePart.Size.Z/2,growablePart.Size.Z/2))
				growingmodule.plantSadzonka(drzewo1,nazwabiomu,pozycja,growablePart)
			end
		end
		until #regionTreeModel:GetChildren() >= limitdrzew
end)

regionTreeModel.ChildAdded:Connect(function(child)
	local sappling = child:FindFirstChild("Drewno")
	growingmodule.rosniecieLoop(sappling,drzewo1,growspeed)
end)
1 Like

You should try to add a “;” after the first function’s end and see if that works. :+1:

1 Like

i tried already but ima try again

nope it does not help

let me just write some random words here because the reply has to be atleast 30 letters

Can you show us how you’re calling the function?

sure just let me edit the post real quick

Well I’m not sure if that would be it but usually when I run functions through a module what I do is this;

local Module= {}

function Module.NameFunction()
end

return Module

as I said I have no idea if your way of calling functions in a module actually works so I can’t say for sure that that’s what it is but you should try changing it and letting me know if that did trick.

nah this does not fix the issue for me

Do you know how to use the Lua debugger? It’s perfect for situations like these where code is not firing, so you can see exactly where your code’s logic flows.

Regarding your code, it looks like the module’s function is called when ChildAdded event is fired. Have you checked whether the ChildAdded event fires at all? According to the order of the code, the repeat loop (where parts are added to regionTreeModel) is performed before the events are connected, which would mean that parts added while in the loop would not be caught by the ChildAdded event.

thanks gonna try it out now or later

ok so i put a print in the childadded function and it looks like thats the issue. im gonna try to find out whats wrong and fix it, thanks

weird i have never had an issue like that

Try this:

local module = {}

function module:FunctionName()
end

return module