Function in module always returns nil

I’m so confused about this, for me it doesn’t even make sense.
So, I created module something like stunning for certain amount of time. I wanted to implement metamethods there(even without them it doesn’t seem to work). I used __call metamethod which fires when table being called as function. BUT, the main problem is that it doesn’t seem to return boolean as it should?? It returns nil…

local mt = {}
local module = {}
local Stunned = {} --table i have problem with
setmetatable(module,mt)



function Stun(Character,Time)
	coroutine.resume(coroutine.create(function()
		local Humanoid = Character.Humanoid
		if Stunned[Character] then return end
		
		Stunned[Character] = true--you can see im setting to true???
		Humanoid.WalkSpeed = 0
		Humanoid.AutoRotate=false
		Humanoid.JumpPower=0
		
		wait(Time)
		
		Stunned[Character] = false -- and then to false...
		Humanoid.WalkSpeed = 16
		Humanoid.AutoRotate=true
		Humanoid.JumpPower=50
	end))	
end


mt.__call = function(self,...)
	local args = {...}
	local call = args[1]
	
	
	if call=="GET" then

		local chr = args[2]
		return Stunned[chr] --returns nil????
	end
	if call=="STUN" then
		local chr = args[2]
		local tim = args[3]
		
		Stun(chr,tim)
	end
	
end





return module

And to add, the module is in ServerStorage, it does return value only with commandbar. ( not in any scripts(im using modulescript but i tried default script, i also tried parenting module to workspace )

What is written in the script calling the module function?

Module("GET")

???

module("GET", Player.Character)

And just to be certainly clear, you are calling

Module("STUN",Player.Character,Time)

first?

Yes, I do that too…

30

Interesting. If you wouldn’t mind, could you attach the server script that calls the module? With the current information I have no idea what could cause this. Thanks!

Nevermind, seems like it works. I was confused because I was adding it in command bar but it still said that it’s nil, seems like if I do that out of bar it works perfectly fine :thinking:

Sorry for taking your time :sweat_smile:

Don’t worry about it. You’re fine! I am glad you figured it out. The reason it probably didn’t work in command bar was because I don’t think you can do everything you normally can from a script. Have a good day!

1 Like