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

Breaking door when Humanoid.health <= 0 not working,help?

I have a door model,and the doorknob haves Humanoid and the part of it is called "Head" ,the door part is called "Torso",So,the doorknob receives the damage correctly,but the door doesn't open,help!

while true do
	if script.Parent.Humanoid.Health <= 0 then
	script.Parent.Torso.CanCollide = false
	script.Parent.Torso.Transparency = 1
	script.Parent.Head.Transparency = 1
	script.Parent.Door2.CanCollide = true
	script.Parent.Door2.Transparency = 0
	script.Parent.Handle2.Transparency = 0
	end
end

4 comments

3

You might want to look into event listeners. Also, this script should've crashed your studio. If you have an infinite or extremely extensive loop with no delay, studio will crash.

0

phleg event listeners is just a complicated way to say event right?

0

oh nvm

2 answers

As Phlegethon said, this is not working, and you're studio is probarly crashing because your while loop is gonna be running and looping infinitly without a delay between each times it loops. So you gotta add a wait in your loop. Orrrrr you can make this way better by using the Died event, so there's no need to put it in a while loop cuz an event doesn't have to be looped, it can be called if something happens at any times, but of course not always. Always use the died event its useful and better than checking if health is == 0.

script.Parent.Died:Connect(function()
    script.Parent.Torso.CanCollide = false
    script.Parent.Torso.Transparency = 1
    script.Parent.Head.Transparency = 1
    script.Parent.Door2.CanCollide = true
    script.Parent.Door2.Transparency = 0
    script.Parent.Handle2.Transparency = 0
end)
 

Easy peasy you just find the guy's health on zero and HULK SMASH the door open!

There is a Health property in Humanoid in Character.

if game.Workspace.YourUsernameHere.Humanoid.Health == 0 then door.Parent = nil end

Don't thank me, I don't want it.

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