This repository has been archived by the owner on Mar 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibInstUtil.lua
58 lines (53 loc) · 2.32 KB
/
LibInstUtil.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
--[[
File name: LibInstUtil.lua
Author: RadiatedExodus (RealEthanPlayz/RealEthanPlayzDev/ItzEthanPlayz_YT)
--]]
local LibInstUtil = {}
--// function <number> LibInstUtil.CalculateTotalMass(inst: Instance)
function LibInstUtil.CalculateTotalMass(inst: Instance): number
assert(typeof(inst) == "Instance", [[LibInstUtil: invalid argument #2 to 'Create' (Instance expected, got ]]..typeof(inst)..[[)]])
if inst:IsA("BasePart") then
return inst.Mass
elseif inst:IsA("Model") then
local masscount = 0
for _, v in pairs(inst:GetDescendants()) do
if v:IsA("BasePart") then
masscount += v.Mass
end
end
return masscount
end
end
--// function <Instance> LibInstUtil.Create(classname: string, data: table)
function LibInstUtil.Create(classname: string, data: table): Instance
assert(typeof(classname) == "string", [[LibInstUtil: invalid argument #1 to 'Create' (string expected, got ]]..typeof(classname)..[[)]])
assert(typeof(data) == "table", [[LibInstUtil: invalid argument #2 to 'Create' (table expected, got ]]..typeof(classname)..[[)]])
local newinst = Instance.new(classname)
local parentpropertyavailable = nil
for property, value in pairs(data) do
if not property == "Parent" then
newinst[property] = value
else
parentpropertyavailable = value
end
end
if parentpropertyavailable then newinst.Parent = parentpropertyavailable end
parentpropertyavailable = nil
return newinst
end
--// function <void> LibInstUtil.SetAllBasePartTransparency(inst: Instance, newtransparency: number)
function LibInstUtil.SetAllBasePartTransparency(inst: Instance, newtransparency: number)
assert(typeof(inst) == "Instance", [[LibInstUtil: invalid argument #1 to 'SetAllBasePartTransparency' (Instance expected, got ]]..typeof(inst)..[[)]])
assert(typeof(newtransparency) == "Instance", [[LibInstUtil: invalid argument #2 to 'SetAllBasePartTransparency' (number expected, got ]]..typeof(newtransparency)..[[)]])
if inst:IsA("BasePart") then
inst.Transparency = newtransparency
else
for _, v in pairs(inst:GetDescendants()) do
if v:IsA("BasePart") then
v.Transparency = newtransparency
end
end
end
return
end
return LibInstUtil