0% found this document useful (0 votes)
1 views5 pages

DestructionModule.lua

The document defines a Lua module for managing collision groups and effects on parts in a game environment. It includes functions for making parts fly up, burn, freeze, and destroy, while managing their attributes and visual effects like smoke and sparks. The module ensures that parts are properly handled and restored after a specified duration, enhancing gameplay interactions with physics-based elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views5 pages

DestructionModule.lua

The document defines a Lua module for managing collision groups and effects on parts in a game environment. It includes functions for making parts fly up, burn, freeze, and destroy, while managing their attributes and visual effects like smoke and sparks. The module ensures that parts are properly handled and restored after a specified duration, enhancing gameplay interactions with physics-based elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

local module = {}

local PhysicsService = game:GetService("PhysicsService")


local cloneCollisionGroupName = "Parts"
local TweenService = game:GetService("TweenService")

local function setupCollisionGroups()


local groups = PhysicsService:GetCollisionGroups()
local groupExists = false
for _, group in ipairs(groups) do
if group == cloneCollisionGroupName then
groupExists = true
break
end
end

if not groupExists then


PhysicsService:CreateCollisionGroup(cloneCollisionGroupName)
end

PhysicsService:CollisionGroupSetCollidable(cloneCollisionGroupName,
cloneCollisionGroupName, false)
end
function module.FlewUpParts(v, duration)
if v:IsA("BasePart") and v.Parent and v.Parent:IsA("Model") then
local parentModel = v.Parent
if not parentModel:GetAttribute("IsBeingDestroyed") then
parentModel:SetAttribute("IsBeingDestroyed", true)

if parentModel:GetAttribute("Destroyable") then
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored = true
p.CanCollide = false
p.Transparency = 1
p:SetAttribute("Destroyable", false)

local clone = p:Clone()

clone.Anchored = false
clone.CanCollide = true
clone.Transparency = 0
clone.CollisionGroup = cloneCollisionGroupName

local smoke =
game.ReplicatedStorage.VFX.SMOKE:Clone()
smoke.Parent = clone
smoke.Color =
ColorSequence.new(clone.BrickColor.Color)
wait(0.0002)
for _, v in ipairs(clone:GetDescendants()) do
if v:IsA("ParticleEmitter") and v.Name ==
"SMOKE" then
if v then
v.Enabled = true
v:Emit(20)
print("Emitting particles
from", v.Name)
end
end
end
clone.AssemblyLinearVelocity = Vector3.new(0,
math.random(50, 80), 0) +
clone.CFrame.RightVector * math.random(-
30, 30) +
clone.CFrame.LookVector * math.random(-
30, 30)
clone.AssemblyAngularVelocity =
Vector3.new(math.random(-8, 8), math.random(-8, 8), math.random(-8, 8))
clone.Parent = workspace

local fadeOutTweenInfo = TweenInfo.new(1,


Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local fadeOutTween = TweenService:Create(clone,
fadeOutTweenInfo, {Transparency = 1})

task.delay(duration - 1, function()
fadeOutTween:Play()
fadeOutTween.Completed:Connect(function()
clone:Destroy()
end)
end)
end
end

task.delay(duration, function()
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored = true
p.CanCollide = true
p.Transparency = 0
p:SetAttribute("Destroyable", true)
end
end

parentModel:SetAttribute("IsBeingDestroyed", false)
end)
end
end
end
end

function module.Destroy(v, duration)


if v:IsA("BasePart") and v.Parent and v.Parent:IsA("Model") then
local parentModel = v.Parent
if not parentModel:GetAttribute("IsBeingDestroyed") then
parentModel:SetAttribute("IsBeingDestroyed", true)

if parentModel:GetAttribute("Destroyable") then
v.Anchored = true
v.CanCollide = false
v.Transparency = 1
v:SetAttribute("Destroyable", false)

task.delay(duration, function()
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") and p ~= v then
p.Anchored = true
p.CanCollide = true
p.Transparency = 0
p:SetAttribute("Destroyable", true)
end
end
v.Anchored = true
v.CanCollide = true
v.Transparency = 0
v:SetAttribute("Destroyable", true)

parentModel:SetAttribute("IsBeingDestroyed", false)
end)
end
end
end
end

function module.BurnParts(v, duration)


if v:IsA("BasePart") and v.Parent and v.Parent:IsA("Model") then
local parentModel = v.Parent
if not parentModel:GetAttribute("IsBeingDestroyed") then
parentModel:SetAttribute("IsBeingDestroyed", true)

if parentModel:GetAttribute("Destroyable") then
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored = true
p.CanCollide = false
p.Transparency = 1
p:SetAttribute("Destroyable", false)

local clone = p:Clone()

clone.Anchored = false
clone.CanCollide = true
clone.Transparency = 0
clone.CollisionGroup = cloneCollisionGroupName
clone.BrickColor = BrickColor.new("Really
black")

local sparks =
game.ReplicatedStorage.VFX.FireSparks:Clone()
sparks.Parent = clone

local smoke =
game.ReplicatedStorage.VFX.SMOKE:Clone()
smoke.Parent = clone
smoke.Color =
ColorSequence.new(clone.BrickColor.Color)
wait(0.0002)
for _, v in ipairs(clone:GetDescendants()) do
if v:IsA("ParticleEmitter") and v.Name ==
"SMOKE" then
if v then
v.Enabled = true
v:Emit(20)
print("Emitting particles
from", v.Name)
end
end
end
clone.AssemblyLinearVelocity = Vector3.new(0,
math.random(50, 80), 0) +
clone.CFrame.RightVector * math.random(-
30, 30) +
clone.CFrame.LookVector * math.random(-
30, 30)
clone.AssemblyAngularVelocity =
Vector3.new(math.random(-8, 8), math.random(-8, 8), math.random(-8, 8))
clone.Parent = workspace

local fadeOutTweenInfo = TweenInfo.new(1,


Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local fadeOutTween = TweenService:Create(clone,
fadeOutTweenInfo, {Transparency = 1})

task.delay(duration - 1, function()
fadeOutTween:Play()
fadeOutTween.Completed:Connect(function()
clone:Destroy()
end)
end)
end
end

task.delay(duration, function()
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored = true
p.CanCollide = true
p.Transparency = 0
p:SetAttribute("Destroyable", true)
end
end

parentModel:SetAttribute("IsBeingDestroyed", false)
end)
end
end
end
end

function module.FreezeParts(v, duration)


if v:IsA("BasePart") and v.Parent and v.Parent:IsA("Model") then
local parentModel = v.Parent
if not parentModel:GetAttribute("IsBeingDestroyed") then
parentModel:SetAttribute("IsBeingDestroyed", true)

if parentModel:GetAttribute("Destroyable") then
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored = true
p.CanCollide = false
p.Transparency = 1
p:SetAttribute("Destroyable", false)

local clone = p:Clone()


clone.Anchored = false
clone.CanCollide = true
clone.Transparency = 0
clone.CollisionGroup = cloneCollisionGroupName
clone.Color = Color3.fromRGB(170, 255, 255)
clone.Material = Enum.Material.Ice
clone.Parent = workspace
local smoke =
game.ReplicatedStorage.VFX.SMOKE:Clone()
smoke.Parent = clone
smoke.Color =
ColorSequence.new(clone.BrickColor.Color)
wait(0.0002)
for _, v in ipairs(clone:GetDescendants()) do
if v:IsA("ParticleEmitter") and v.Name ==
"SMOKE" then
if v then
v.Enabled = true
v:Emit(20)
print("Emitting particles
from", v.Name)
end
end
end
game.Debris:AddItem(clone,duration)
end
end

task.delay(duration, function()
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored = true
p.CanCollide = true
p.Transparency = 0
p:SetAttribute("Destroyable", true)
end
end

parentModel:SetAttribute("IsBeingDestroyed", false)
end)
end
end
end
end

return module

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy