Functions Inside ModuleScript Functions

If I wanted to use functions within a ModuleScript function, they don’t work. How would I do this properly?

An example would look like this:

local Module = {}

function Module.CarScript()
	function destroyWheels()
		local Wheel = script.Parent.Car.Wheel
		Wheel:Destroy()
	end

	destroyWheels()
end

return Module

Thanks :slight_smile:

1 Like

You can have the function outside the main function like this:

local Module = {}

function destroyWheels()
	local Wheel = script.Parent.Car.Wheel
	Wheel:Destroy()
end

function Module.CarScript()
	destroyWheels()
end

return Module

Just add local in the beggining of each function

1 Like

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