How can I use modules?

I have a problem about modules. When I test my module it says nil value in output.

Here is the other script:

messagemoduler = require(script.Parent.ModuleScript)
messagemoduler.ChatCommand()
1 Like

Please include the module and all the scripts that use the module so we can help you

And Here is the output:

the error seems to be that OnPlayerEntered is created under OnChatted

function onChatted(msg, recipent, speaker)
	msg = string.lower(msg)
	if (msg == message) then
		shopgui:TweenPosition(UDim2.new(0.5, 0,0.5, 0), 'Out', 'Bounce', '1')
	end
	function onPlayerEntered(newplayer) --This should be outside of onChatted
		newplayer.Chatted:Connect(function(msg, recipent)onChatted(msg,recipent,newplayer) end)
	end
end
game.Players.PlayerAdded:Connect(onPlayerEntered)

should become

function onChatted(msg, recipent, speaker)
	msg = string.lower(msg)
	if (msg == message) then
		shopgui:TweenPosition(UDim2.new(0.5, 0,0.5, 0), 'Out', 'Bounce', '1')
	end
end

function onPlayerEntered(newplayer)
	newplayer.Chatted:Connect(function(msg, recipent) onChatted(msg,recipent,newplayer) end)
end
game.Players.PlayerAdded:Connect(onPlayerEntered)

Thank you it helped me. My module is now working. And sorry for posting very shortly in the first post.

1 Like

In the future, when you want to post code to the forums, please actually post the code rather than a screenshot so we can better assist you. Copy the part of the code that you have trouble with, then paste it between a code block.

```lua
-- Your code here
```

This will allow us to better help you when someone says “please post code”. They aren’t looking for a screenshot, they’re looking for actual text that they can modify or inspect.

Thank you I will use that in my future posts. I am new in dev forum so I did not know that.