Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why is this module script call not working? [simple]

Hi im new in module scripts and im practicing it. I made 2 functions in a module script and, the first one I call works fine, the second one I call doesn't fire at all. I don't know why sinse im calling them just like the first one:

-- Script inside a part:

local Necronomicon = require(game.ServerStorage.Necronomicon)

spawn(Necronomicon.ChangingColorsLoop(script.Parent))
spawn(Necronomicon.HooverLoop(script.Parent))
-- module script called Necronomicon who the script above reffers to:

local module = {}
	-- Changing colors loop using color list module--------------------------
	function module.ChangingColorsLoop(part)
		local colors = require(game.ServerStorage.ColorList) 
		while wait(2) do
			part.BrickColor = colors[math.random(1, #colors)]
		end
	end
	
	
	-- 1x1 hoovering---------------------------------------------------------
	function module.HooverLoop(part) print("not")
		if part:FindFirstChild("BodyAngularVelocity") == nil then
			local bav = Instance.new("BodyAngularVelocity", part)
			local bp = Instance.new("BodyPosition", part)
			bav.AngularVelocity = Vector3.new(0,0.6,0.1)
			bp.D = 2000
			bp.MaxForce = Vector3.new(4000,500,4000)
			bp.P = 10000
			bp.Position = part.Position		
		end
		local direction = "down"
		while wait(1.5) do
			if direction == "down" then
				direction = "up"
				part.BodyPosition.Position = part.BodyPosition.Position - Vector3.new(0,1,0)
			elseif direction == "up" then
				direction = "down"
				part.BodyPosition.Position = part.BodyPosition.Position + Vector3.new(0,1,0)
			end
		end
	end


return module

Nothing showing in output

10 comments

0

Let's try this, put some print statements in the module functions and see if any of them print out. If some of them do then that means your module functions are being called. I would do this myself but I don't have your "ColorList."

0

The function for the colors are working fine, but the function for hoovering is not firing.I've tried putting a print right after the function name and it doesn't print... Im lost.

0

I mean, you see that "print("not")" in line 14?

1

Ah yes, I do see the print. And After removing the color changing function I do get a print out of "not" in my console. As well the function is working and the part I have is floating?

0

hmmmmmm thanks, so how can I define multiple functions in the same module script?

0

I took this method from the wiki, im seeing no difference... https://developer.roblox.com/en-us/api-reference/class/ModuleScript

0

You did it right.

0

Oh it looks like that "spawn" is not working

1

Try using spawn(function() YOUR FUNCTION HERE end)

1 answer

Solved. Instead of writing:

spawn(Necronomicon.HooverLoop(script.Parent))
spawn(Necronomicon.ChangingColorsLoop(script.Parent))

I should write:

spawn(function() Necronomicon.HooverLoop(script.Parent) end)
spawn(function() Necronomicon.ChangingColorsLoop(script.Parent) end)

1 comment

0

;)

This discussion is preserved as it was. New answers, comments, and votes are closed.