Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local module = {}
- --[[
- Author: TigerCaptain
- Date: 22/09/2018
- Usage example:
- local thanos = require("Thanos")
- thanos:Vanish(workspace.Model)
- API:
- @params object: an instance object, if it is a part, it will only run on that part,
- but if it is not a part, then it will run on all of its descendants.
- Vanish( Instance object )
- PROPERTIES:
- tween_info: The TweenInfo object, storing the tween pattern for all parts
- base_properties: A base property for all tweening objects
- --]]
- local TS = game:GetService("TweenService")
- local tween_info = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
- local base_properties = {Transparency = 1}
- --[[
- This function copies the <original> table and returns it
- @params original: the original table you are copying
- @return: a copy of the original table
- --]]
- local function CopyTable(original)
- local t = {}
- for i,v in pairs(original) do
- if type(v) == "table" then
- t[i] = CopyTable(v)
- else
- t[i] = v
- end
- end
- return t
- end
- --[[
- This function combines the <new> table with <base_properties>
- @params new: the additional table you want to merge with the base_properties
- @return: the combined table
- --]]
- local function AddProperties(new)
- local prop = CopyTable(base_properties)
- for i,v in pairs(new) do
- prop[i] = v
- end
- return prop
- end
- --[[
- This function sorts objects based on its position in the world.
- @params: part1, part2: These two will be compared
- @return: true if part1 is further from origin (0,0,0) than part2
- --]]
- local function AngleSort(part1, part2)
- local s1, s2 = part1.Position, part2.Position
- return s1.Magnitude > s2.Magnitude
- end
- --[[
- This function will return a table of all the descendants in the parent
- @params: parent: The parent holding all descendants
- class (optional): will sort all descendants of a single class
- TODO: Make it a list of classes
- @return: A table of descendants, filtered if desired
- --]]
- local function GetDescendants(parent, class)
- local all_descendants = parent:GetDescendants()
- if class == nil then return all_descendants end
- local filtered_descendants = {}
- for i,v in pairs(all_descendants) do
- if v:IsA(class) then
- filtered_descendants[#filtered_descendants+1] = v
- end
- end
- return filtered_descendants
- end
- --[[
- This function directly runs the tween on an object
- @params: part: the part being changed
- --]]
- local function VanishPart(part)
- local properties = AddProperties({CFrame = part.CFrame + part.Position.unit*10})
- local tween = TS:Create(part, tween_info, properties)
- tween:Play()
- end
- --[[
- This function goes through all base parts in a parent directory and applies the
- VanishPart() method upon it.
- @params: model: the directory to run upon.
- --]]
- local function VanishModel(model)
- local descendents = GetDescendants(model, "BasePart")
- table.sort(descendents, AngleSort)
- for i,v in pairs(descendents) do
- v.Anchored = true
- VanishPart(v)
- if i%3 == 0 then
- wait()
- end
- end
- end
- --[[
- This method determines what function to call depending on its object type
- @params: object: the instance to apply the function
- --]]
- function module:Vanish(object)
- if object:IsA("BasePart") then
- VanishPart(object)
- else
- VanishModel(object)
- end
- end
- return module
Add Comment
Please, Sign In to add comment