InTesting

My Custom RLua Functions (UFunctions)

May 29th, 2020 (edited)
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.87 KB | None | 0 0
  1. --[[
  2.     CHL's functions
  3.      by CHL/SoftlockedUnderZero
  4.    
  5.     Place code in a module script.
  6.    
  7.     Here comes obnoxious comments lol
  8.    
  9.     This script will include:
  10.      + a Services dictionay
  11.      + a coroutine2 library
  12.       + run
  13.      + an Instance2 libary
  14.       + new
  15.       + new2
  16.      + a math2 library
  17.       + average
  18.       + euler
  19.       + round
  20.       + round2
  21.      + a table2 library
  22.       + add
  23.       + changevalues
  24.       + changevalues2
  25.       + foreach
  26.       + foreacha
  27.       + foreachi
  28.       + getindexes
  29.       + len
  30.       + lena
  31.       + randomvalue
  32.       + replicate
  33.      + a remote library
  34.       + RemoteArray
  35.       + GetRemoteEvent
  36.       + GetRemoteFunction
  37.       + FireServer
  38.       + FireClient
  39.       + InvokeServer
  40.       + InvokeClient
  41.       + FireAllClients
  42.       + ServerHandler
  43.       + ClientHandler
  44.      + a string2 library
  45.       + replace
  46.       + multisplit
  47.       + StringToByte
  48.      + global apairs function
  49.      + global wait2 function
  50.      + global spawn2 function
  51.      + global delay2 function
  52.      + global DecalIdToImageId function
  53.      + global GetPlayerFromSubString function
  54.      + global toboolean function
  55.      + global WaitForChild function
  56.      + global ProcessReciept2 function
  57.      + global WaitForChildWhichIsA function
  58.      + global LoadstringEnabled function
  59.      + global LoadLibrary2 function
  60.      + global MethodToContructorFunction function
  61.      + global IsVSB function
  62.      + global ContentURL string
  63.      + global GetObjects2 function
  64.      + global GetPlayerFromCharacterDescendant function
  65.      + global FindFirstChildren function
  66.      + global WaitForAncestorWhichIsA function
  67.      + global TeleportCharacter function
  68.      + global TeleportAllCharacters function
  69.      + global YieldUntil function
  70.      + global PlayerHandler function
  71.      + global CharacterHandler function
  72.      + global tocontentstring function
  73.      + global DamagePart function
  74.      + global CheckVariable function
  75.      + global printtable function
  76.      + global CheckGlobalVariable function
  77.      + global effects library
  78.       + Text section
  79.        + Typewriter effect
  80.      + global GetUpdatedName function
  81.      + global CFrame2 library
  82.       + AnglesRad
  83.       + PositionOrientationToCFrame function  In testing
  84.       + CFrameToPositionOrientation function  In testing
  85.      + PhysicsServiceFunctions library
  86. --]]
  87.  
  88. local CHL_Functions = {
  89.     Services = { -- Services table
  90.         Players = game:GetService("Players");
  91.         RunService = game:GetService("RunService");
  92.         MarketplaceService = game:GetService("MarketplaceService");
  93.         ReplicatedStorage = game:GetService("ReplicatedStorage");
  94.         UserInputService = game:GetService("UserInputService");
  95.         KeyframeSequenceProvider = game:GetService("KeyframeSequenceProvider");
  96.         ServerStorage = game:GetService("ServerStorage");
  97.         PhysicsService = game:GetService("PhysicsService");
  98.         HttpService = game:GetService("HttpService")
  99.     };
  100.     CFrame2 = {
  101.         AnglesRad=function(x,y,z)local a=math.rad;return CFrame.Angles(a(x),a(y),a(z))end;
  102.     };
  103.     coroutine2 = {
  104.         run = function(a)local b = coroutine.wrap(a);b();return b;end;
  105.         --[[It's a quicker way of saying .wrap(func)(), except it also returns the thread.
  106.             Arguments:
  107.                 M (function)
  108.             Returns:
  109.                 (thread)
  110.         --]]
  111.     };
  112.     effects = {
  113.         Text = {
  114.             Typewriter = function(text,waitincrementtime,nospaceyield,object,property)
  115.                 local function d(b,c)
  116.                     for a=1,#text do
  117.                         local letter = text:sub(a,a);
  118.                         b[c] = text:sub(1,a);
  119.                         if nospaceyield and letter==' 'then continue;end;
  120.                         wait(waitincrementtime);
  121.                     end;
  122.                 end;
  123.                 if object and property then
  124.                     d(object,property)
  125.                 else
  126.                     return d;
  127.                 end;
  128.             end;
  129.             --[[Yielding current script, this types each letter one by one until the result is finished.
  130.                 If unprovided an object, then it will return a function instead.
  131.                 Arguments:
  132.                     M (string)
  133.                     M (number)
  134.                     O (boolean-type)
  135.                     O (Instance)
  136.                     O (string)
  137.                 Returns:
  138.                     (If unprovided an instance and property)
  139.                         (function) With parameters equal to the fourth and fifth original parameters.
  140.             --]]
  141.         };
  142.        
  143.     };
  144.     Instance2 = {};
  145.     math2 = {
  146.         euler = 2.7182818284590452353602874713527;
  147.         --//euler's constant number (shorted because the real number is irrational like math.pi)
  148.         round = function(a)return math[a<math.ceil(a)-.5 and'floor'or'ceil'](a)end
  149.         --[[This function rounds to the ones place. Note: to round to other number places you have
  150.             to either use math2.round2 or do the math outside of the function
  151.             Arguments:
  152.                 M (number)
  153.             Returns:
  154.                 M (number)
  155.         --]]
  156.     };
  157.     PhysicsServiceFunctions = {};
  158.     remote = {RemoteArray = {Instance.new("RemoteEvent");Instance.new('RemoteFunction');};};
  159.     string2 = {
  160.         replace = function(main,replacements)for a,b in pairs(replacements)do main=string.gsub(main,a,b);
  161.             end;return main;end;
  162.         --[[Functions like gsub but you can replace mulitple words as one dictionary.
  163.             Arguments:
  164.                 M (string)
  165.                 M (table)  A Dictionary where the index is the target string and the value is the new
  166.                     replacement
  167.             Returns:
  168.                 M (string) The new result.
  169.         --]]
  170.         multisplit = function(a,...)a={a;};for _,b in pairs{...;}do local c={};for _,d in pairs(a)do
  171.             local g=string.split(d,b);for f,e in pairs(g)do table.insert(c,e);if #g==f then continue;end;
  172.             table.insert(c,b);end;end;a=c;end;if not table.find({...;},'')then local d={};for b,c in pairs(a)
  173.             do if c~=''then continue;end;table.insert(d,b);end;for b in pairs(d)do table.remove(a,d[#d-b+1]);
  174.             end;end;return a;end;
  175.         --[[Like string.split, it returns an array. But it also returns values that also include the
  176.             seperator. You can also put more than one seperator in the tuple arguments.
  177.             Arguments:
  178.                 M (string)
  179.                 M (tuple)  All strings.
  180.             Returns:
  181.                 (table)
  182.         --]]
  183.         StringToBytes=function(string_1)return'\\'.. table.concat({string.byte(string_1,1,#string_1),'\\'})end;
  184.         --[[Returns a string where the string is converted to byte already formatted with the backward slashes
  185.             Arguments:
  186.                 M (string)
  187.             Returns:
  188.                 (string)
  189.         --]]
  190.     };
  191.     table2 = {
  192.         add = function(table1)local b = 0;for _,a in pairs(table1)do b = b + a;end;return b;end;
  193.         --[[Adds each value of a given table and gives the sum.
  194.             Arguments:
  195.                 M (table) table_of_numbers
  196.             Returns:
  197.                 (Number) The sum of each value
  198.         --]]
  199.         changevalues = function(table1,newvalues,isprinted)for a,b in pairs(newvalues)do
  200.             local _,c=pcall(function()table1[a]=b;end);if isprinted and c then warn('So'
  201.             ..'mething went wrong while changing a value: Index = '..a..', Value = '..b);end;end;end;
  202.         --[[Changes the table's index with the new value. Similar with Table.Index = Value, except it
  203.             can be done with a table.
  204.             Arguments:
  205.                 M (table)        Table_that_will_be_changing (or instance)
  206.                 M (table)        Table_that_will_do_the_changing
  207.                 O (boolean-type) If true, then the function will warn if something went wrong.
  208.         --]]
  209.         foreach = function(table_a,function_a)local c = {};for a,b in pairs(table_a)do c[a] = function_a(a,b);
  210.             end;return c;end;
  211.         --//Functions and structured like table.foreach except it returns a table of results and can yield
  212.         foreachi = function(table_a,function_a)local c = {};for a,b in ipairs(table_a)do c[a] = function_a(a,b);
  213.             end;return c;end;
  214.         --//Functions and strucured like table.foreachi and has similar behavior like table2.foreach
  215.         getindexes = function(a)assert(a,'argument 1 missing')local c = {};for b in pairs(a)do
  216.             table.insert(c,b);end;return c;end;
  217.         --[[Returns an array of each index from a given dictionary.
  218.             Arguments:
  219.                 M (table)
  220.             Returns:
  221.                 M (table)
  222.         --]]
  223.         replicate = function(table_a)local a = {};for b,c in pairs(table_a)do a[b]=c;end;return a;end;
  224.         --[[Creates a new table with the index and values exactly like the old one.
  225.             Arguments:
  226.                 M (table) Old table
  227.             Returns:
  228.                 (table) New table
  229.         --]]
  230.     };
  231.     toboolean = function(a)return not not a;end;
  232.     --[[Returns a boolean-type value into a boolean.
  233.         Arguments:
  234.             O (Boolean-type)
  235.         Returns:
  236.             (boolean)
  237.     --]]
  238.     LoadstringEnabled = function(String)local a = pcall(function()loadstring'return""'();end);
  239.         if not a then return;end;if String then return loadstring(String);end;return loadstring;end;
  240.     --[[Returns nil if loadstring is not enabled, but returns the function if it is (depending on the first
  241.         argument).
  242.         Arguments:
  243.             O (string) If there's a string, the function will return a loadstring called function, otherwise,
  244.                 it will return loadstring itself.
  245.         Returns:
  246.             (variant)
  247.                 (nil) Only if loadstring is not enabled.
  248.                 (function)
  249.                     > loadstring itself if the first argument is empty.
  250.                     > loadstring called with the string provided.
  251.     --]]
  252.     LoadLibrary2 = function()return require(4675891912);end;
  253.     --[[Functions like loadlibrary but when called with "CloneSelf", it clones a module version of itself.
  254.         Note: you have to call this first then call another time to apply arguments.
  255.         Arguments:
  256.             M (string) Same strings like loadlibrary plus "CloneSelf".
  257.         Returns:
  258.             (Variant) Same value returned like loadlibrary except if the string is "CloneSelf", it returns
  259.                 a module which can be required like this function itself, you can not use "CloneSelf" again.
  260.     --]]
  261.     GetArrayBasedOnClassName=function(a,b)local c={};for _,d in pairs(a)do if not d:IsA(b)then continue;
  262.         end;table.insert(c,d);end;return c;end;
  263.     --[[Returns an array from a given table which contains the classname given.
  264.         Arguments:
  265.             M (table)
  266.             M (string) classname
  267.         Returns:
  268.             (table)
  269.     --]]
  270.     MethodToContructorFunction = function(a,b)return function(...)return a[b](a,...);end;end;
  271.     --[[Converts a method to a constructure function. This does not change the table.
  272.         Arguments:
  273.             M (table)
  274.             M (string)
  275.         Returns:
  276.             (function)
  277.     --]]
  278.     ContentURL = 'http://www.roblox.com/asset/?id=';
  279. };
  280.  
  281.  
  282.  
  283. --// Instance2 \\--
  284. CHL_Functions.Instance2.new = function(ClassName,Properties)local a = Instance.new(ClassName);
  285.     CHL_Functions.table2.changevalues(a,Properties or{},0);return a;end;
  286. --[[Creates a new instance with the second arg being that it changes the instances properties.
  287.     Arguments:
  288.         M (string)     Classname of the instance.
  289.         O (dictionary) A dictionary where the properties are changed.
  290.     Returns:
  291.         (Instance)     Instance
  292. --]]
  293. CHL_Functions.Instance2.new2 = function(ClassName)return function(Properties)
  294.     return CHL_Functions.Instance2.new(ClassName,Properties);end;end;
  295. --//Functions and structiured like LoadLibraries "Create" function
  296.  
  297.  
  298.  
  299.  
  300. --// math2 \\--
  301. CHL_Functions.math2.average = function(...)return CHL_Functions.table2.add{...;}/#{...;};end;
  302. --[[Returns the average of the tuple
  303.     Arguments:
  304.         M (tuple) ...
  305.     Returns
  306.         (number) the average from the sum from the tuple
  307. --]]
  308.  
  309.  
  310.  
  311. --// table2 \\--
  312. CHL_Functions.table2.changevalues2 = function(table1,isprinted)return function(Properties)
  313.     CHL_Functions.table2.changevalues(table1,Properties,isprinted)end;end;
  314. --//Same function as table2.changevalues but structured like LoadLibrary's Create.
  315. CHL_Functions.table2.foreacha = function(table1,function_a)for a,b in pairs(table1)do if tonumber(a)then
  316.     continue;end;function_a(a,b);end;end;
  317. --//Structed like foreachi except it accepts a dictionary instead of arrays.
  318. CHL_Functions.table2.len = function(a)return#CHL_Functions.table2.getindexes(a);end;
  319. --[[Returns a number like operator # but it also includes both indexes and keys.
  320.     Arguments:
  321.         M (table)
  322.     Returns:
  323.         (number)
  324. --]]
  325. CHL_Functions.table2.lena=function(a)local b=0;for _ in CHL_Functions.apairs(a)do b=b+1;end;return b;end;
  326. --//Functions and structured like table2.len except it only counts indexes.
  327. CHL_Functions.table2.randomvalue=function(a)assert(a,'argument 1 missing');local c={};for _,b in pairs(a)do
  328.     table.insert(c,b);end;return c[math.random(1,#c)];end;
  329. --[[Returns a random value from the array.
  330.     Arguments:
  331.         M (table)
  332.     Returns:
  333.         (variant) depends what's on the array.
  334. --]]
  335.  
  336.  
  337.  
  338. --// remote \\--
  339.  
  340. CHL_Functions.remote.GetRemoteEvent = function()
  341.     return CHL_Functions.table2.randomvalue(CHL_Functions.GetArrayBasedOnClassName(CHL_Functions.remote.
  342.         RemoteArray,'RemoteEvent'));end;
  343. --[[Returns a random remoteevent.
  344.     Returns:
  345.         (Instance) RemoteEvent
  346. --]]
  347. CHL_Functions.remote.GetRemoteFunction = function()
  348.     return CHL_Functions.table2.randomvalue(CHL_Functions.GetArrayBasedOnClassName(CHL_Functions.remote.
  349.         RemoteArray,'RemoteFunction'));end;
  350. --//Same thing as remote.GetRemoteEvent but returns a RemoteFunction
  351.  
  352. CHL_Functions.remote.FireServer = function(...)CHL_Functions.remote.GetRemoteEvent():FireServer(...);end;
  353. CHL_Functions.remote.FireClient = function(...)CHL_Functions.remote.GetRemoteEvent():FireClient(...);end;
  354. CHL_Functions.remote.InvokeServer = function(...)
  355.     return CHL_Functions.remote.GetRemoteFunction():InvokeServer(...);end;
  356. CHL_Functions.remote.InvokeClient = function(...)
  357.     return CHL_Functions.remote.GetRemoteFunction():InvokeClient(...);end;
  358. CHL_Functions.remote.FireAllClients = function(...)
  359.     CHL_Functions.remote.GetRemoteEvent():FireAllClients(...);
  360. end;
  361. --//It's self explainitory
  362.  
  363.  
  364.  
  365. CHL_Functions.remote.ServerHandler = function(a)
  366.     for _,b in pairs(CHL_Functions.remote.RemoteArray)do
  367.         if b:IsA'RemoteEvent'then
  368.             b.OnServerEvent:Connect(a);
  369.         elseif b:IsA'RemoteFunction'then
  370.             b.OnServerInvoke = a;
  371.         end;
  372.     end;
  373. end;
  374. CHL_Functions.remote.ClientHandler = function(a)
  375.     for _,b in pairs(CHL_Functions.remote.RemoteArray)do
  376.         if b:IsA'RemoteEvent'then
  377.             b.OnClientEvent:Connect(a);
  378.         elseif b:IsA'RemoteFunction'then
  379.             b.OnClientInvoke = a;
  380.         end;
  381.     end;
  382. end;
  383. --[[This funciton is used to merge OnServerEvent and OnServerInvoke and viceversa with client functions
  384.     if called differently
  385. --]]
  386.  
  387.  
  388.  
  389. --// other globals \\--
  390. CHL_Functions.apairs = function(table_a)local b = pairs(table_a);local e = {};for c,d in pairs(table_a)do
  391.     if typeof(c)=='number'then continue;end;e[c]=d;end;return b,e;end;
  392. --//Structured like "pairs" and "ipairs" except only runs on indexes of "strings" not numbers.
  393.  
  394. CHL_Functions.spawn2 = CHL_Functions.coroutine2.run;
  395. --//Functions and structured exactly like roblox's "spawn", but faster.
  396. local spawn = CHL_Functions.spawn2;
  397.  
  398. CHL_Functions.wait2 = function(WaitTime)--yes this is swait
  399.     local Stepped = CHL_Functions.Services.RunService.Stepped;
  400.     if not WaitTime or WaitTime==0 then local _,a = Stepped:Wait();return a;
  401.     else local a = 0;repeat local _,b = Stepped:Wait();a=a+b;until a>=WaitTime;return a;end;end;
  402. --[[Similar to roblox's global "wait" except it uses runservice's Stepped to yield the current thread.
  403.     Arguments:
  404.         O (number) wait_time
  405.     Returns:
  406.         (number) amount of seconds passed
  407. --]]
  408. local wait = CHL_Functions.wait2;
  409.  
  410. CHL_Functions.delay2 = function(WaitTime,function_a)spawn(function()wait(WaitTime);function_a();end);end;
  411. --//Functions and structured exactly like roblox's "delay".
  412. local delay = CHL_Functions.delay2;
  413.  
  414. CHL_Functions.DecalIdToImageId = function(id)
  415.     local GetProductId = function(a)return CHL_Functions.Services.MarketplaceService:GetProductInfo(a);end;
  416.     local info = GetProductId(id);
  417.     if info.AssetTypeId~=13 then return;end;
  418.     local author = info.Creator.Name;
  419.     repeat
  420.         wait();
  421.         id = id - 1;
  422.         local newinfo = GetProductId(id);
  423.         if newinfo.AssetTypeId~=1 then continue;end;
  424.         if author~=newinfo.Creator.Name then continue;end;
  425.         return id;
  426.     until nil;
  427. end;
  428. --[[Returns the image id of a decal. This can yield the current thread.
  429.     Arguments:
  430.         M (number) Decal id.
  431.     Returns:
  432.         (number) Image id.
  433. --]]
  434.  
  435. CHL_Functions.GetPlayerFromSubString = function(substring)assert(substring,'Argument 1 missing or nil');
  436.     substring = substring:lower():reverse();for _,a in pairs(CHL_Functions.Services.Players:GetPlayers())do
  437.     local b = (a.Name):lower():reverse();if not string.find(b,substring,#b-#substring)then continue;end;
  438.     return a;end;end;
  439. --[[Returns a player from a given substring, returns nil if it can't find one. Ex, if the substring is
  440.     'potato' and a player named "potatowow" is here, then it returns the player, however, it will not return
  441.     "wowpotato" because "potato" is at the end. Note: this does not account for the length of the name
  442.     Arguments:
  443.         M (string) Substring at the beginning of the target player's name.
  444.     Returns:
  445.         (Instance) Target Player.
  446. --]]
  447.  
  448. CHL_Functions.WaitForChild = function(Parent,Name,TimeOut,GetDescendant,WaitTime)
  449.     assert(Parent and Name,'Arguments missing.');
  450.     local b = 0;
  451.     repeat
  452.         local a = Parent:FindFirstChild(Name,CHL_Functions.toboolean(GetDescendant));
  453.         if a then return a;end;
  454.         b = b + wait(WaitTime or 0);
  455.         if TimeOut and TimeOut>b then return;end;
  456.     until nil;
  457. end;
  458. --[[Yields current script and returns the child. Difference between this and the already implemented
  459.     "WaitForChild" is that it won't throw a warning if you leave the timeout number blank.
  460.     Arguments:
  461.         M (Instance)     Target Parent.
  462.         M (string)       Name.
  463.         O (number)       Time out in seconds.
  464.         O (boolean-type) If true, it finds descendants.
  465.         O (number)       Increment for wait time.
  466.     Returns:
  467.         (Instance) Child
  468. --]]
  469.  
  470. CHL_Functions.WaitForChildWhichIsA = function(Parent,ClassName,TimeOut,GetDescendant,WaitTime)
  471.     assert(Parent and ClassName,'Arguments missing.');
  472.     local b = 0;
  473.     repeat
  474.         local a = Parent:FindFirstChildWhichIsA(ClassName,CHL_Functions.toboolean(GetDescendant));
  475.         if a then return a;end;
  476.         b = b + wait(WaitTime or 0);
  477.         if TimeOut and TimeOut>b then return;end;
  478.     until nil;
  479. end;
  480. --[[Similar to WaitForChild except it uses classname instead of name.
  481.     Arguments:
  482.         M (Instance)     Target Parent.
  483.         M (string)       ClassName.
  484.         O (number)       Time out in seconds.
  485.         O (boolean-type) If true, it finds descendants.
  486.         O (number)       Increment for wait time.
  487.     Returns:
  488.         (Instance) Child
  489. --]]
  490. CHL_Functions.ProcessReciept2 = function(f)return function(a)
  491.     return(f(a)and Enum.ProductPurchaseDecision.PurchaseGranted)or Enum.ProductPurchaseDecision.
  492.     NotProcessedYet;end;end;
  493. --[[Similar to the original ProcessReceipt,except structured so that and false-type values will return
  494.     Enum.ProductPurchaseDecision.NotProcessedYet and any true-type values will return
  495.     Enum.ProductPurchaseDecision.PurchaseGranted
  496.     Arguments:
  497.         M (function)
  498.     Returns:
  499.         (function) now use this like ProcessReciept
  500. --]]
  501.  
  502. CHL_Functions.IsVSB = function()return not not table.find({843495510;843468296;897312463;},game.PlaceId);end;
  503. --[[Returns a boolean if the specific script is in VSB.
  504.     Returns:
  505.         (boolean)
  506. --]]
  507.  
  508. CHL_Functions.GetObjects2 = function(a)return game:GetObjects(CHL_Functions.ContentURL..a);end;
  509. --[[Functions like GetObjects except this function already concats the contenturl with the assetid
  510. --]]
  511.  
  512. CHL_Functions.GetPlayerFromCharacterDescendant = function(a)
  513.     if not a then return;end;
  514.     a = a:FindFirstAncestorWhichIsA'Model';
  515.     if not a then return;end;
  516.     return CHL_Functions.Services.Players:GetPlayerFromCharacter(a);
  517. end;
  518. --//Returns the player if the instance is a descendant of their character.
  519.  
  520. CHL_Functions.FindFirstChildren = function(Parent,Children)for _,a in pairs(Children)do
  521.     Parent = Parent:FindFirstChild(a);if not Parent then return;end;end;return Parent;end;
  522. --[[Similar with FindFirstChild(...,'true') except it goes down the descendant tree to find it.
  523.     Arguments:
  524.         M (Instance) Parent
  525.         M (Array) An array of strings of the name of the children.
  526.     Returns:
  527.         (Instance)
  528. --]]
  529.  
  530. CHL_Functions.WaitForAncestorWhichIsA = function(Parent,Name,TimeOut,Increment)
  531.     local b = 0
  532.     repeat
  533.         local a = Parent:FindFirstAncestorWhichIsA(Name);
  534.         if a then return a;end;
  535.         local c = wait(Increment or 1/60)
  536.         b = b + c;
  537.         if TimeOut then
  538.             if b>=TimeOut then break;end;
  539.         end;
  540.     until nil;
  541. end;
  542. --//Self explanitory if you read the other functions.
  543.  
  544. CHL_Functions.TeleportCharacter = function(Player,Position,CharacterOffset)
  545.     assert(CHL_Functions.Services.RunService:IsClient(),'no')
  546.     assert(Player and Position,'args 1 and 2 missing');
  547.     local a = Player.Character;
  548.     if typeof(Position)=='Instance'then Position = Position.CFrame;end;
  549.     if CharacterOffset then Position = Position + Vector3.new(0,3,0);end;
  550.     if not a then Player:LoadCharacter();a = Player.Character or Player.CharacterAdded:Wait();end;
  551.     a = a:FindFirstChild'HumanoidRootPart';
  552.     if not a then return;end;
  553.     a.CFrame = Position;
  554. end;
  555. --[[Teleports the player's character to a position.
  556.     Arguments:
  557.         M (Instance)                      Player
  558.         M (CFrame or Instance or Vector3) Position
  559.         O (boolean-type)                  Automatically offsets character upwards if true.
  560. --]]
  561.  
  562. CHL_Functions.TeleportAllCharacters = function(Position,Players,CharacterOffSet)
  563.     assert(Position,'args 1 missing');
  564.     for _,a in pairs(Players or CHL_Functions.Services.Players:GetPlayers())do
  565.         CHL_Functions.TeleportCharacter(a,Position,CharacterOffSet);
  566.     end;
  567. end;
  568. --[[Functions like TeleportCharacter but it can do all players or a specific set of them.
  569.     Arguments:
  570.         M (CFrame or Instance or Vector3) Position
  571.         O (table)                         An array of players who have been chosen to get teleported.
  572.                                             If blank, the array will be all players.
  573.         O (boolean-type)                  Automatically offsets character upwards if true.
  574. --]]
  575.  
  576. CHL_Functions.YieldUntil = function(ActionFunction,TimeOut,Increment,...)
  577.     local a = 0;
  578.     while''do
  579.         local b = ActionFunction(...);if b then return b;end;
  580.         a = a + wait(Increment or 0);if TimeOut and TimeOut<a then break;end;
  581.     end;
  582. end;
  583. --[[Yields current thread and repeatedly calls the ActionFunction until the ActionFunction returns a value.
  584.     Basically the same as:
  585.         repeat
  586.             -- ...
  587.         until nil
  588.     Arguments:
  589.         M (function)  Repeatedly called until a value is returned.
  590.         O (number)    Time out in seconds.
  591.         O (Increment) Time it takes to call the next function after calling the previous one.
  592.         O (tuple)     Arguments used on the ActionFunction.
  593.     Returns:
  594.         (variant)
  595. --]]
  596.  
  597. CHL_Functions.PlayerHandler = function(a)CHL_Functions.Services.Players.PlayerAdded:Connect(a);
  598.     for _,b in pairs(CHL_Functions.Services.Players:GetPlayers())do a(b);end;end;
  599. --[[A function which is called for every player in the server and for each new player added.
  600.     Arguments:
  601.         M (function)
  602. --]]
  603.  
  604. CHL_Functions.CharacterHandler = function(a)CHL_Functions.PlayerHandler(function(b)if b.Character then
  605.     a(b.Character);end;b.CharacterAdded:Connect(a);end);end;
  606. --//Structured like PlayerHandler except called on the player's character or when a character is added.
  607.  
  608. CHL_Functions.tocontentstring = function(a)return CHL_Functions.ContentURL..tostring(a);end;
  609. --//Returns a string form of content with the id.
  610.  
  611. CHL_Functions.DamagePart = function(Part,Damage,ActionFunction,InstantDeathHealthCapacity,OnlyLimbs)
  612.     assert(Part,'no part');Damage = Damage or 1;ActionFunction = ActionFunction or function()end;
  613.     local a = (OnlyLimbs and Part.Parent)or Part:FindFirstAncestorWhichIsA'Model';if not a then return;end;
  614.     local b = a:FindFirstChildWhichIsA'Humanoid'or a:FindFirstChild('Head')or a:FindFirstChid('Torso')or
  615.         a:FindFirstChild'UpperTorso';
  616.     if b then
  617.         if b:IsA'BasePart'then b:Destroy();ActionFunction();
  618.         elseif b:IsA'Humanoid'then b:TakeDamage(Damage);
  619.             if InstantDeathHealthCapacity and b.Health>InstantDeathHealthCapacity then b.Health = 0;end;
  620.             ActionFunction();end;
  621.     else pcall(function()b:BreakJoints();ActionFunction();end);end;
  622. end;
  623. --[[Damages the character but better. Any part which is a descendant of the character will get damaged
  624.     and not its children. The function also provides an action function which is called when the character
  625.     has been successfully damaged. DamagePart also provides a max health capacity which instantly kills the
  626.     player if their health is over the parameter and an onlylimbs parameter which reduces the hitbox of the    
  627.     character from the character with accessories to just the character itself.
  628.     Arguments:
  629.         M (Instance)
  630.         O (Number)
  631.         O (function)
  632.         O (number)      
  633.         O (boolean-type)
  634. --]]
  635.  
  636. CHL_Functions.CheckVariable = function(a)
  637.     assert(CHL_Functions.LoadstringEnabled(),'loadstring not enabled, unable to use this');
  638.     return loadstring('return '..a)();
  639. end;
  640. --[[Returns the variable regardless whether its local and global. Difference is that the variable is writen as a
  641.     string and the variable must be in the block. There will be no warnings in the script.
  642.     Arguments:
  643.         M (string)
  644.     Returns:
  645.         (variant)
  646. --]]
  647.  
  648. CHL_Functions.printtable = function(a)CHL_Functions.table2.foreach(a,print);end;
  649. --[[Prints the table with key and value side to side. Mainly used for debuging purposes.
  650.     Arguments:
  651.         M (table)
  652. --]]
  653.  
  654. CHL_Functions.CheckGlobalVariable = function(a)return getfenv()[a];end;
  655. --//Same as CheckVariable but only for globals. The upside is that it does not require loadstring.
  656.  
  657. CHL_Functions.GetUpdatedName = function(a)local b=CHL_Functions.Services.Players;
  658.     return b:GetNameFromUserIdAsync(b:GetUserIdFromNameAsync(a));
  659. end;
  660. --[[Returns the current updated name from an input of an old name
  661.     Parameters:
  662.         M (string)
  663.     Returns:
  664.         (string)
  665. --]]
  666. CHL_Functions.CFrame2.PositionOrientationToCFrame=function(p,o)local a,b=CFrame,CHL_Functions.CFrame2.AnglesRad;
  667.     return a.new(p)*b(0,0,o.Z)*b(0,o.Y,0)*b(o.X,0,0);
  668. end;
  669. CHL_Functions.CFrame2.CFrameToPositionOrientation=function(c)local a,b,d={c:GetComponents()},Vector3.new,math.deg;
  670.     local c={c:ToOrientation()}return b(a[1],a[2],a[3]),b(d(c[1]),d(c[2]),d(c[3]));
  671. end;
  672. CHL_Functions.PhysicsServiceFunctions.FindGroup = function(name)
  673.     local a = CHL_Functions.Services.PhysicsService;
  674.     for _,b in next,a:GetCollisionGroups()do
  675.         if b.name==name then
  676.             return b;
  677.         end;
  678.     end;
  679. end;
  680. CHL_Functions.PhysicsServiceFunctions.CreateGroup = function(name)
  681.     local a = CHL_Functions.Services.PhysicsService;
  682.     local b = CHL_Functions.PhysicsServiceFunctions.FindGroup(name)
  683.     if b then return b;end;
  684.     return a:CreateCollisionGroup(name)
  685. end
  686. CHL_Functions.math2.round2 = function(a,b)b=10^(b or 0)return CHL_Functions.math2.round(a*b)/b;end
  687. --[[Same function as math2.round but with a new parameter where the number is muliplied with 10 ^ x beforehand
  688.     so that math2.round can run to a specific number place
  689.     Arguments:
  690.         M (number)
  691.         O (number)
  692.     Returns:
  693.  
  694.  
  695. --]]
  696.  
  697. return CHL_Functions;
Add Comment
Please, Sign In to add comment