Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make an Instance.new("Explosion") applied to all parts in the group via in pairs loop?

Asked by 2 years ago
Edited 2 years ago

I have tried this, but only 1 random part in the group of 10 parts explodes, but I want so all 10 parts explode

local e = Instance.new("Explosion")

wait(1)
for i,part in pairs(workspace.ExplosivePartsGroup:GetChildren()) do
    e.Parent = part
    e.Position = part.Position
    e.BlastRadius = 5
    e.BlastPressure = 100000
    e.DestroyJointRadiusPercent = 1
end

I tried to do same thing but without in pairs loop but it says error in output:

Workspace.PartsExplodeScript:25: invalid argument #3 (Instance expected, got table)

Code:

local e = Instance.new("Explosion")
local part = workspace.ExplosivePartsGroup:GetChildren()

e.Parent = part
e.Position = part
e.BlastRadius = 5
e.BlastPressure = 100000
e.DestroyJointRadiusPercent = 1

1 answer

Log in to vote
0
Answered by
aazkao 787 Moderation Voter
2 years ago
Edited 2 years ago

You are instantiating a new explosion outside the loop, so the explosion only happens once and then gets parented to 10 different blocks, it needs to be in the loop for the explosion to happen 10 times on 10 different blocks

for i,part in pairs(workspace.ExplosivePartsGroup:GetChildren()) do
    local e = Instance.new("Explosion")
    e.Parent = part
    e.Position = part.Position
    e.BlastRadius = 5
    e.BlastPressure = 100000
    e.DestroyJointRadiusPercent = 1
end

For your second problem You need to read up on how GetChildren()works, it returns a table, the table contains all instances of the parts you want to explode, so you have to use a for loop such as in pairs to loop through the instances and apply the explosion

0
Thank you, now it's working correctly slimeking12399 6 — 2y
Ad

Answer this question