I’m trying to use the function coroutine.wrap()
so that I can make it so that my function doesn’t yield, as I fire the function 5 times to spawn a copy of a bomb that goes through a long process, and it yields.
I saw another post that told me that coroutine.wrap()
doesn’t yield the function that its connected to, but after inserting it into my code, for some reason I get this error.
18:41:59.584 Workspace.Cluster Bomb.PlantBomb:224: missing argument #1 to 'wrap' (function expected) - Server - PlantBomb:224
18:41:59.584 Stack Begin - Studio
18:41:59.585 Script 'Workspace.Cluster Bomb.PlantBomb', Line 224 - function explode - Studio - PlantBomb:224
18:41:59.585 Script 'Workspace.Cluster Bomb.PlantBomb', Line 240 - Studio - PlantBomb:240
18:41:59.585 Stack End - Studio
Here’s the code.
function miniBombExplode(miniBomb, user)
for i = 1, 3 do task.wait(.75)
tickSound:Play()
end
task.wait(1)
miniBomb.Anchored = true
local explosionParticle = miniBomb.Explosion
explosionSound:Play()
miniBomb.Transparency = 1
miniBomb.Decal.Transparency = 1
local region3 = Region3.new(
miniBomb.Position - Vector3.new(blastRegion3L/2, 1, blastRegion3W/2),
miniBomb.Position + Vector3.new(blastRegion3L/2, blastRegion3H/2, blastRegion3W/2)
) -- Creates a region3 that destroys any parts in the explosions radius.
local region3Visual = Instance.new("Part") -- The visualized part for the region3.
region3Visual.Name = "blastRadiousVisual"
region3Visual.CanCollide = false
region3Visual.Size = Vector3.new(blastRegion3L, blastRegion3H, blastRegion3W)
region3Visual.CFrame = region3.CFrame
region3Visual.Anchored = true
region3Visual.Transparency = .5
region3Visual.Parent = miniBomb
region3Visual.BrickColor = BrickColor.new("Persimmon")
local explosion = Instance.new("Explosion", miniBomb) -- The explosion instance
explosion.Position = miniBomb.Position
explosion.BlastRadius = 0
explosion.DestroyJointRadiusPercent = 0
explosion.BlastPressure = 1000000
explosion.BlastRadius = blastRegion3L
local overlapParams = OverlapParams.new()
overlapParams.FilterDescendantsInstances = {tool, tool.Handle, region3Visual}
local parts = workspace:GetPartBoundsInBox(region3.CFrame, region3.Size, overlapParams)
explosion.Hit:Connect(function(Part)
if Part.Name == "HumanoidRootPart" then
local character = Part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player and player.Team ~= user.Team then
character:FindFirstChildOfClass("Humanoid"):TakeDamage(baseDamage)
if character:FindFirstChildOfClass("Humanoid").Health == 0 then
user.leaderstats.Kills.Value += 1
end
end
end
end)
for i, v in pairs(parts) do
if v.Name == "Brick" then
v.Anchored = false
v.CanTouch = false
v.BrickColor = user.TeamColor
for i, constraint in pairs(v:GetChildren()) do
if constraint:IsA("Snap") or constraint:IsA("Weld") or constraint:IsA("WeldConstraint") then
constraint:Destroy()
end
end
task.delay(3, game.Destroy, v)
end
if v.Name == "GameBrick" then v.Name = "TaggedGameBrick" -- TaggedGameBricks are GameBricks in the game that have been effected by the bomb, while regular Bricks are just bricks you can destroy by default.
v.Anchored = false
v.CanTouch = false
user.leaderstats.Bricks.Value += 1 -- The total bricks the player has broken throughout the round.
user["T. Bricks"].Value += 1 -- The total bricks that the player has destroyed throughout there playtime
user.leaderstats.Studs.Value += .1 -- Increases the players currency (Studs) by 0.1.
v.BrickColor = user.TeamColor -- Changes the taggedBricks color to the local players team color to show that they have broken the part.
task.delay(3, game.Destroy, v) -- later deletes the part.
end
end
task.delay(3, game.Destroy, miniBomb)
task.wait(2)
explosionParticle.Enabled = false -- Disables the explosion particles.
end
....
for i = 0, 5, 1 do
local miniBombClone = Mini_Bomb:Clone()
miniBombClone.Parent = workspace.Bombs
miniBombClone.Position = bomb.Position + Vector3.new(math.random(-4, 4), 4, math.random(-4, 4))
coroutine.wrap(miniBombExplode(miniBombClone, user))
end