Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

can i do this so the loop ends when the enemy dies?

while enemy.Name == "IzziWorm" do --Constantly checking.
    if enemy.SlimeWormModel.SlimeProjectileIzzi then --Checking if it exists
        enemy.SlimeWormModel.SlimeProjectileIzzi:Destroy() --Destroying the object
    end
end

2 comments

1

Why not use the Died event of a Humanoid to determine when it died?

0

If your enemy has a humanoid inside of it, then you can easily do what DeathCaster suggested with more functionality than just having loops and if statements like you do here. I'll even type up an answer to show you how you could use it.

2 answers

✓ Accepted answer

Yes, Simply add an else statement

while enemy.Name == "IzziWorm" do --Constantly checking.
    if enemy.SlimeWormModel.SlimeProjectileIzzi then --Checking if it exists
        enemy.SlimeWormModel.SlimeProjectileIzzi:Destroy() --Destroying the object
    else --if it doesn't exist
    	break --then it breaks the loop
    end
end

2 comments

0

so if i do the while loop it causes an error somewhere else in the script

0

You really shouldn't need a pcall() in this case. Make sure your enemy is there and the children of your objects are there with findFirstChild(). It's better to assume something may not be there. 

So using the Died event allows you to have more options in the future and is an overall easier method for checking if a humanoid died than using an if statement.

So it seems like the enemy we are checking for to see if it is dead or not is the "IzziWorm", so I am just going to go ahead and use that as the model containing the humanoid.

enemy.IzziWorm.Died:Connect(function()
	if enemy.SlimeWormModel.SlimeProjectileIzzi then --Checking if it exists
        	enemy.SlimeWormModel.SlimeProjectileIzzi:Destroy() --Destroying the object
    	end
end

So what I am assuming is happening just judging by the functionality of your code in the question is that if the IzziWorm dies, you want it to destroy the IzziWorm's projectile.

This way allows you to check if the IzziWorm dies without having to have a possible infinite loop while maintaining the same functionality as what you had before.

If you feel this is a better solution, then please mark this as the accepted answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.