Instance won't create after being hit

bullet.Touched:Connect(function(hit)
				task.wait(0.1)
				bullet:Destroy()
				if hit.Parent ~= player.Character then -- so localPlayer does not get damaged
					if hit then
						if hit.Parent:FindFirstChild("Humanoid") then
							if hit.Name == "Head" then
								hit.Parent:FindFirstChild("Humanoid"):takeDamage(headshot)
							else
								hit.Parent:FindFirstChild("Humanoid"):takeDamage(damage)
							end
							if hit.Parent:FindFirstChild("Part") then -- finds first child of hit
								if hit.Name == "Water" then -- if Part's name is Water
									local waterP = Instance.new("ParticleEmitter")
									waterP.Parent = bullet
									waterP.Texture = "http://www.roblox.com/asset/?id=129418678"
									waterP.Size = 2
									waterP.LightEmission = 1
									waterP.LightInfluence = 1
									waterP.Lifetime = 1
									waterP.Rate = 20
									waterP.Speed = 10
									waterP.Drag = 4
									task.wait(0.1)
									waterP:Destroy()
								end
							end

for some reason, when the bullet touches the part, the WaterP instance isn’t created. I have no idea why, but I’ll ask here.

1 Like

I would say it’s because you’re destroying the bullet before parenting something to it.

1 Like

No, because I am doing a 0.1 sec yield before destroying it, giving the Instance the opportunity to parent.

The destruction runs before any of the if statements though. Not sure where your logic is coming from, but the destruction of the bullet will always come first in this situation.

1 Like

you’re destroying the bullet before you’re parenting WaterP to it, reverse the order

1 Like

I tried putting it at the end of the script, but it still doesn’t create the instance. Where do you think I should put the bullet:Destroy()?

Try adding some prints to check where the conditions are leading to false and not running. Putting the destroy after the conditions and creating the instance is the best option (I would still recommend turning the bullet invisible and anchoring it before the if statements and creation of the instance).

I have added prints, but it appears that the bullet does not register that it touched the water, however, this works for humanoids?

Looking at the conditions, does the water have a humanoid? Is the water supposed to have a part named “Part” underneath its parent? It’s kind of confusing how you put the conditions.

Error message:

attempt to call field ‘takeDamage’ (a nil value)

Stack trace:

[C]: in function ‘takeDamage’
main.lua:19: in function main.lua:10

main.lua:10: in function ‘connect’

main.lua:10: in function main.lua:1

Quick summary

I am creating an instance, but the instance won’t create after being hit by a bullet.

Thanks in advance!

–DuckBoss

Edit: This isn’t a script issue. It’s a place issue.