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

Is there any way to make when you kill a NPC that a Part changes...?

Hello,is there any way to make when you kill a NPC that a Part changes Collision and Transparenty?

2 comments

0

By part do you mean the NPCs collision and Transparency change when it dies?

0

No,when a NPC dies that a Brick changes the Collision and Transparenty.

1 answer

✓ Accepted answer

Hello, Great_Strategy!

My name is TheOnlySmarts and I am here to help you!

Let's begin, shall we?

So in order to change a Part's properties after an NPC is dead, we'll need to use a simple repeat wait() until loop.

The loop waits and waits until something has changed or a new event has triggered or occurred. In our example, we're going to repeat wait() until our NPC is dead.

In this case I will be implementing a regular Dummy into the Workspace. I am also going to insert a regular Part and scale it until it's almost a door. I anchor the part to stop it from falling to the ground. Now what you want to do is place a regular script inside of the part and begin typing.

So in order to script experienced we need to keep our script nice and neat. So instead of typing out large and un-needed lines of code every single time, we're going to develop some variables. A variable just keeps information in a safe compartment, it is also helpful when you need to call this variable often.

dummyH = game.Workspace:WaitForChild("Dummy"):FindFirstChild("Humanoid")
num = 0

Now as you can see I've just labelled the Dummy's Humanoid and the Number needed to be in order to die. You may of also noticed that I am not inserting local at the start of each variable since we aren't creating something, but defining something that has been already created. You would use local when you're using Instance.new, etc etc, but for now; we're fine.

Now we need to loop!

dummyH = game.Workspace:WaitForChild("Dummy"):FindFirstChild("Humanoid")
num = 0

repeat wait() until dummyH.Health == num

Basically what we're doing is repeating wait() until the dummy's health is equal to 0. Now all we have to do is change the properties of the part doing so!

dummyH = game.Workspace:WaitForChild("Dummy"):FindFirstChild("Humanoid")
num = 0

repeat wait() until dummyH.Health == num

script.Parent.CanCollide = false
script.Parent.Transparency = 0.5

Ta-dah! Try it out for yourself and let me know if it's working, if you're curious on something, contact me through the comments below and I will try and help you as best as I can!

If you feel you have learnt something from me, please Accept the Answer; it really means a lot!

3 comments

0

Thank you so much TheOnlySmarts!It really helped!

0

Wow this was an good awsner. He explained what he did and teached him too. Defintly good effort in this!

0

Thank you all for the positive feedback! Have fun scripting!

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