Am I using modules properly?

Hello devs! today I started learning on how module scripts work, and even though I already have the jist of how they work, I dont know if what im doing is how they should be used

For context im trying to make a simple FPS script

local module = {}

module.TestAnim = nil
module.AnimTrack = Animator:LoadAnimation(TestAnim)

module:MouseClick()
     --gun go pew
     AnimTrack:Play()
end

return module

Now obviously this code when required will error, but how else would you reference the humanoids animator? Should I even be using variables in module scripts to reference things the say way I do in normal scripts?

Thanks in Advance!

First of all, where are you going to place this module? If it’s going to run on the client, you can just do game.Players.LocalPlayer to reference the player object. If it’s on the server, you can create a function inside the module and pass the player when you call it from a script

Modules are just a way of having your code more organized and easy to edit but you can still make local variables in them

1 Like

Thanks for the help! didn’t realize you could just:

module.Player = game:GetService("Players").LocalPlayer

No problem, just keep in mind that it will only work if it’s running on the client and you can also use local to declare variables! :slightly_smiling_face:

1 Like

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