I,v in pairs loop not going through all of a table

So im making a sticky launcher where you can fire stickies and detonate them all at once.
My problem is the fact that I dont think my i,v in pairs loop is not going through all of the Stickies table, which leads to…
image|322x205
not all of them exploding.
I have tried doing an i = 1, #Stickies, 1 do loop and putting in local v = Stickies[1] which did nothing.
I have no idea on how to fix this, I’ve looked for solutions on dev forum already but to no avail.
And here is the section of code that I’m talking about

for i,v in pairs(Stickies) do
	local Explosion = Instance.new("Explosion")
	Explosion.BlastPressure = 500000
	Explosion.BlastRadius = 8
	Explosion.Position = v.Position
	Explosion.DestroyJointRadiusPercent = 0
	Explosion.Parent = workspace
	Explosion.Hit:Connect(function(touchpart)
		if touchpart.Parent:FindFirstChild("Humanoid") then
			touchpart.Parent:FindFirstChild("Humanoid"):TakeDamage(35 / 6)
		end
	end)
	local SoundPart = Instance.new("Part")
	SoundPart.Size = Vector3.new(0.01, 0.01, 0.01)
	SoundPart.Anchored = true
	SoundPart.CanCollide = false
	SoundPart.Transparency = 1
	SoundPart.Position = v.Position
	SoundPart.Parent = workspace
	local Sound = explodesounds[math.random(1, #explodesounds)]:Clone()
	Sound.Parent = SoundPart
	Sound:Play()
	game.Debris:AddItem(SoundPart, 7)
	print(Stickies)
	print(i)
	table.remove(Stickies, i)
	v:Destroy()
end

Have you tried using ipairs? It’s the table iterator.

nope, still didnt explode all of them at a time

It’s because you’re removing them while you’re iterating. Clear the table after iteration.

2 Likes

okay, will try that
thanks for helping mate

for i,v in pairs(Stickies) do
	local Explosion = Instance.new("Explosion")
	Explosion.BlastPressure = 500000
	Explosion.BlastRadius = 8
	Explosion.Position = v.Position
	Explosion.DestroyJointRadiusPercent = 0
	Explosion.Parent = workspace
	Explosion.Hit:Connect(function(touchpart)
		if touchpart.Parent:FindFirstChild("Humanoid") then
			touchpart.Parent:FindFirstChild("Humanoid"):TakeDamage(35 / 6)
		end
	end)
	local SoundPart = Instance.new("Part")
	SoundPart.Size = Vector3.new(0.01, 0.01, 0.01)
	SoundPart.Anchored = true
	SoundPart.CanCollide = false
	SoundPart.Transparency = 1
	SoundPart.Position = v.Position
	SoundPart.Parent = workspace
	local Sound = explodesounds[math.random(1, #explodesounds)]:Clone()
	Sound.Parent = SoundPart
	Sound:Play()
	game.Debris:AddItem(SoundPart, 7)
	print(Stickies)
	print(i)
end

while #Stickies > 0 do
	table.remove(Stickies, #Stickies)
	#Stickies:Destroy()
end

its a miracle
it works! thanks for helping out

Hey, mark the post which has been solved! So that others can know if your question has been solved or not!

1 Like

all done
thanks for reminding me
this is the first time ive used devforum to post a topic because i normally use scripting helpers

1 Like