I am working on a ModuleScript to contain nearly every function a scripter will need in their code.
Sounds like a tedious job I know, but I’m up for it
So far I’ve added string functions (string.format() etc), services, math (math.random() etc) and ray functions.
I also added a GetWorkspaceObject and GetObjectInService function which searches descendants for the object which is acquired from the argument.
I’m asking what functions would you like to see in it & which do you use the most?
I would create a function called :MakeRay(start,direction)
It would create a ray, with the following parameters. If direction is a Vector3 value, then it calculates the direction by doing (start - direction).Unit * 300, (Like how you would script a gun)
function module:WeldBetween(part0, part1)
local w = Instance.new("Weld")
w.P0 = part0
w.P1 = part1
w.C0 = part0.CFrame * part1.CFrame:inverse()
w.Parent = part0
return w
end
Another useful function would be a method to get a list of characters given a collection of parts (such as when you use workspace:FindPartsInRegion3() ex:
function module:FindCharactersInList(list)
local chars = {}
local foundChars = {}
for _, part in next, list do
if part.Parent:FindFirstChild"Humanoid" and not foundChars[part.Parent.Humanoid] then
foundChars[part.Parent.Humanoid] = true
chars[#chars+1] = part.Parent.Humanoid
end
end
return chars
end
I’m so glad someone is doing this! I though about doing something like this but never got around to doing it. I don’t know if this fits into the idea you had for the module but, you could add a leaderstat maker. Or maybe a easy way to create a new instance. Something module:Make(type, parent). I know that this is kind of pointless as it would be easier to use Intance.new. But, with Instance.new you have to put the parent after the obj is instantiated. But with this function you could shorten it to make it a little bit faster. I know that I would use it but I don’t know if it would help anyone or if it would be even effective. It’s just an idea.
Not sure if it would fit every scripter but I’d definitely find a utility which hooks into ChatService and allows you to send messages to players without having to deal with channels and speakers useful
function module:GetModelMass(model)
local Mass = 0
for _,descendant in pairs(model:GetDescendants()) do
if (descendant:IsA("BasePart")) then
Mass = Mass + descendant:GetMass()
end
end
return Mass
end
Not a function, but separate your utilities by type/task/so on so developers can salvage and use parts independent of the grand ModuleScript. Cluttering all kinds of functions into a single ModuleScript can and will get annoying not only for you as a maintainer but a developer as a user of this as well.
Something I have in my module that I’m sure will be useful:
A function that returns the server type; normal, vip or reserved. If it’s a vip server potentially also the server owner. If I had access to my laptop right now I’d provide my code but it’s a bit late.
It may be a bit better because the second argument of Instance.new is not recommended to use (according to a DevForum article). Upon reading this article, I completely ended my habit of using the second argument. It would be a very simple function to run. (The article is from around two and a half years old, so I may be incorrect.)
A function I use a lot is this table randomizer, takes a table as input and returns the same table but the contents inside of it randomized.
function RandomizeTable(tbl)
local newt = {}
for i = 1, #tbl do
local n = math.random(1, #tbl)
table.insert(newt, tbl[n])
table.remove(tbl, n)
end
return newt
end
It’s great that you’re doing this! I don’t know if your module already has the following functions, but one that I know is used a lot is to shorten a number by using SI prefix symbols along with one that keeps a set number of decimals.
Here are some other simple functions that I have in my own module:
Convert dictionary to array
Return the object with the specified value at the designated key in an array of objects (dictionaries)