Kelas Engine
Explosion
*Konten ini diterjemahkan menggunakan AI (Beta) dan mungkin mengandung kesalahan. Untuk melihat halaman ini dalam bahasa Inggris, klik di sini.
Contoh Kode
Instansiasi Ledakan
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- merusak terrain
explosion.Position = Vector3.new(0, 10, 0)
explosion.Parent = workspaceReferensi API
Properti
BlastPressure
Contoh Kode
Ledakan Kustom
local function customExplosion(position, radius, maxDamage)
local explosion = Instance.new("Explosion")
explosion.BlastPressure = 0 -- ini bisa diatur lebih tinggi untuk tetap menerapkan kecepatan pada bagian-bagian
explosion.DestroyJointRadiusPercent = 0 -- sambungan aman
explosion.BlastRadius = radius
explosion.Position = position
-- siapkan tabel untuk melacak model yang terkena
local modelsHit = {}
-- mendengarkan kontak
explosion.Hit:Connect(function(part, distance)
local parentModel = part.Parent
if parentModel then
-- periksa untuk melihat apakah model ini sudah terkena
if modelsHit[parentModel] then
return
end
-- catat model ini sebagai terkena
modelsHit[parentModel] = true
-- cari humanoid
local humanoid = parentModel:FindFirstChild("Humanoid")
if humanoid then
local distanceFactor = distance / explosion.BlastRadius -- ambil jarak sebagai nilai antara 0 dan 1
distanceFactor = 1 - distanceFactor -- balik jumlahnya, sehingga yang lebih rendah == lebih dekat == lebih banyak kerusakan
humanoid:TakeDamage(maxDamage * distanceFactor) -- TakeDamage untuk menghormati ForceFields
end
end
end)
explosion.Parent = game.Workspace
-- Roblox menghapus ledakan setelah beberapa detik, tetapi tidak menghancurkannya.
-- Untuk memastikan koneksi .Hit kita terputus, hancurkan ledakan setelah dihapus.
explosion.AncestryChanged:Connect(function()
if not explosion.Parent then
explosion:Destroy()
end
end)
end
customExplosion(Vector3.new(0, 10, 0), 12, 50)BlastRadius
Contoh Kode
Instansiasi Ledakan
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- merusak terrain
explosion.Position = Vector3.new(0, 10, 0)
explosion.Parent = workspaceDestroyJointRadiusPercent
Contoh Kode
Ledakan non mematikan
local function onDescendantAdded(instance)
if instance:IsA("Explosion") then
local explosion = instance
explosion.DestroyJointRadiusPercent = 0
local destroyJointRadiusPercent = 1
explosion.Hit:Connect(function(part, distance)
-- periksa apakah bagian berada dalam jangkauan untuk memutuskan sambungan
if distance <= destroyJointRadiusPercent * explosion.BlastRadius then
-- pastikan bagian tersebut tidak termasuk karakter
if not game.Players:GetPlayerFromCharacter(part.Parent) then
part:BreakJoints()
end
end
end)
end
end
workspace.DescendantAdded:Connect(onDescendantAdded)Ledakan Kustom
local function customExplosion(position, radius, maxDamage)
local explosion = Instance.new("Explosion")
explosion.BlastPressure = 0 -- ini bisa diatur lebih tinggi untuk tetap menerapkan kecepatan pada bagian-bagian
explosion.DestroyJointRadiusPercent = 0 -- sambungan aman
explosion.BlastRadius = radius
explosion.Position = position
-- siapkan tabel untuk melacak model yang terkena
local modelsHit = {}
-- mendengarkan kontak
explosion.Hit:Connect(function(part, distance)
local parentModel = part.Parent
if parentModel then
-- periksa untuk melihat apakah model ini sudah terkena
if modelsHit[parentModel] then
return
end
-- catat model ini sebagai terkena
modelsHit[parentModel] = true
-- cari humanoid
local humanoid = parentModel:FindFirstChild("Humanoid")
if humanoid then
local distanceFactor = distance / explosion.BlastRadius -- ambil jarak sebagai nilai antara 0 dan 1
distanceFactor = 1 - distanceFactor -- balik jumlahnya, sehingga yang lebih rendah == lebih dekat == lebih banyak kerusakan
humanoid:TakeDamage(maxDamage * distanceFactor) -- TakeDamage untuk menghormati ForceFields
end
end
end)
explosion.Parent = game.Workspace
-- Roblox menghapus ledakan setelah beberapa detik, tetapi tidak menghancurkannya.
-- Untuk memastikan koneksi .Hit kita terputus, hancurkan ledakan setelah dihapus.
explosion.AncestryChanged:Connect(function()
if not explosion.Parent then
explosion:Destroy()
end
end)
end
customExplosion(Vector3.new(0, 10, 0), 12, 50)ExplosionType
Contoh Kode
Hentikan Ledakan dari Merusak Terrain
local function onDescendantAdded(instance)
if instance:IsA("Explosion") then
instance.ExplosionType = Enum.ExplosionType.NoCraters
instance:GetPropertyChangedSignal("ExplosionType"):Connect(function()
instance.ExplosionType = Enum.ExplosionType.NoCraters
end)
end
end
workspace.DescendantAdded:Connect(onDescendantAdded)Position
Contoh Kode
Instansiasi Ledakan
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- merusak terrain
explosion.Position = Vector3.new(0, 10, 0)
explosion.Parent = workspaceVisible
Contoh Kode
Visual Kustom Ledakan
local function customExplosion(position)
local explosion = Instance.new("Explosion")
explosion.Position = position
explosion.Visible = false
local attachment = Instance.new("Attachment")
attachment.Position = position
attachment.Parent = workspace.Terrain
local particleEmitter = Instance.new("ParticleEmitter")
particleEmitter.Enabled = false
particleEmitter.Parent = attachment
particleEmitter.Speed = NumberRange.new(5, 30)
particleEmitter.SpreadAngle = Vector2.new(-90, 90)
explosion.Parent = workspace
particleEmitter:Emit(20)
task.delay(5, function()
if attachment then
attachment:Destroy()
end
end)
end
customExplosion(Vector3.new(0, 10, 0))Acara
Hit
Contoh Kode
Ledakan Kustom
local function customExplosion(position, radius, maxDamage)
local explosion = Instance.new("Explosion")
explosion.BlastPressure = 0 -- ini bisa diatur lebih tinggi untuk tetap menerapkan kecepatan pada bagian-bagian
explosion.DestroyJointRadiusPercent = 0 -- sambungan aman
explosion.BlastRadius = radius
explosion.Position = position
-- siapkan tabel untuk melacak model yang terkena
local modelsHit = {}
-- mendengarkan kontak
explosion.Hit:Connect(function(part, distance)
local parentModel = part.Parent
if parentModel then
-- periksa untuk melihat apakah model ini sudah terkena
if modelsHit[parentModel] then
return
end
-- catat model ini sebagai terkena
modelsHit[parentModel] = true
-- cari humanoid
local humanoid = parentModel:FindFirstChild("Humanoid")
if humanoid then
local distanceFactor = distance / explosion.BlastRadius -- ambil jarak sebagai nilai antara 0 dan 1
distanceFactor = 1 - distanceFactor -- balik jumlahnya, sehingga yang lebih rendah == lebih dekat == lebih banyak kerusakan
humanoid:TakeDamage(maxDamage * distanceFactor) -- TakeDamage untuk menghormati ForceFields
end
end
end)
explosion.Parent = game.Workspace
-- Roblox menghapus ledakan setelah beberapa detik, tetapi tidak menghancurkannya.
-- Untuk memastikan koneksi .Hit kita terputus, hancurkan ledakan setelah dihapus.
explosion.AncestryChanged:Connect(function()
if not explosion.Parent then
explosion:Destroy()
end
end)
end
customExplosion(Vector3.new(0, 10, 0), 12, 50)