I'm trying out module scripts for the first time to increase efficiency in my game, but they seem a little complicated.
So, for example, I use this a lot:
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then -- code end end)
Could I put any of this into a module script? And what would it look like? So instead of having to type out all that I could just do maybe something like
require(TouchedScript) require(HumanoidCheck)
To my knowledge, require is used outside of the modulescript. I still don't exactly know how to use it, but I still use it as a function library. I am not sure how to use it for EVENTS, though...
For example
ModuleScript
local Library={} function Library.CheckHumanoid(Model) if Model:FindFirstChild("Humanoid") then return true else return false end end return Library
ServerScript, inside of a Part with .Touched Event
local Library=require(Workspace:WaitForChild("ModuleScript")) local Part=script.Parent Part.Touched:connect(function(hit) if Library.CheckHumanoid(hit.Parent)==true then hit.Parent:BreakJoints() end end)
--modulescript local t={}; function t.connectTouch(part, func) local con; con=part.Touched:connect(func) end return t;
--script local module=require(Workspace.Blah)--rename it module.connectTouch(script.Parent, function(hit) print(hit.Parent.Name) end)
Something like that would work.