Aura gets deleted and idk why

Hello!

I was working on an aura system for a killstreak pan.

I made a script that gets the aura stuff from a dummy in ServerStorage and then puts the auras in a table named PartName. After that, it gets the children (parts) of the character and clones the auras in the specified place. But, there’s a problem!

In that script, it checks to see if there are auras in the parts of the character and if so, deletes them. But, everytime a good aura spawns in the player’s character, the aura gets removed for some reason.

i don’t know what to do pls help

Script
		local Phase = KillstreakPhases:FindFirstChild("1")
		local PhaseDummy = Phase:FindFirstChild("Dummy")

		for i,v in pairs(PhaseDummy:GetChildren()) do
			local PartName = {}

			if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then

				for i,w in pairs(v:GetChildren()) do
					if w:IsA("ParticleEmitter") or w:IsA("Attachment") then
						local stuff = w:Clone()

						table.insert(PartName, stuff)

						for i,item in pairs(Player.Character[w.Parent.Name]:GetChildren()) do
							for i,a in pairs(PartName) do
								if item:IsA("ParticleEmitter") and item ~= a then
									item:Destroy()
								elseif item:IsA("Attachment") and item.Name == "Attachment" and item ~= a then
									item:Destroy()
								end

								stuff.Parent = Player.Character[w.Parent.Name]
							end
						end
					end
				end
			end
		end
1 Like

Your parenting the clone after the if statement, so while looping trough the partname table the clone is basically nil, try parenting it before the if statement

The flaw with your idea is that it’ll delete everything because the aura has been parented to the character before the check, so it’ll destroy the good aura too and uh yeah it won’t work.

Also I found out that it’s running the second for loop 27 times according to a print() statement.

image

What are you even trying to achieve with 4 for loops? Honestly this thing is a mess and the structure makes zero sense.

You create a particleemitter, then essentially loop over the particleemitters and delete all of them because if it’s a particleemitter, it will always at some point inevitably trigger both of your conditions(Unless there is only one child of w.Parent.Name). And then within that same loop you parent stuff to “w.Parent.Name”, which means it’ll be deleted when the loop for i,a in pairs(PartName) do continues

NVM

You should wait to parent stuff until after the whole code snippet you’ve posted, because even if you move it down past the two for loops, if phasedummy has several children you’ll still end up back at the same place and delete it.

EDIT: Actually nvm the above, i see that PhaseDummy actually is character with several parts, so you can just move it down past the three for loops.

I think you have a serious misunderstanding of what your own code is actually doing right now, and you should probably sit down and try to think about what is actually happening step by step because otherwise you’ll be having these problems over and over. Sketch it out if you have to.

1 Like

i made this trash script at like 1:00 AM
i was super tired and just wanted to finish it
when you told me that the script is a mess, i just looked at it for a second and was like: “yeah, i gotta rewrite this.”
i ended up rewriting it and it works now

thank you for helping me i guess

1 Like

Youre welcome, glad you figured it out and managed to improve it even. Good job.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.