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

How do i make this part transparent when it dies?

I tried to make a model and inside the model there is a humanoid, a part called ''head'' and a script. The health in the humanoid = 100 and the maxhealth = 100. The part called ''head'''s transparency = 0. And i have a sword wich can damage the part until its <= 0 health. So i tried to make the part called ''head'' invisible when it's health = 0 or lower. This is what was inside the script:

function myFunction() if script.Parent.Humanoid.Health <= 0 then script.Parent.Head.Transparency = 1 end end myFunction()

I just started scripting so i'm not the best but can anyone tell me what the problem here is? Thanks :D

2 comments

0

Are you trying to make a players head invisible?

0

Please, just please, use code blocks.

1 answer

✓ Accepted answer
script.Parent.Humanoid.HealthChanged:connect(function()
if script.Parent.Humanoid.Health == 0 then
script.Parent.Head.Transparency = 1 
else
script.Parent.Head.Transparency = 0
end
end)

This script should work.

The problem with your script is that you call the function right after you define it once. when scripts get to the end of a script, they will stop functioning because there is no more code to execute, (unless there are events which i will talk about)

So essentially, in your script, as soon as the function is defined, it runs it once, and then it is done.

Your code was perfect except for that fact and the fact that the transparenxy wont change back.

So, in my solution, I used the "health changed" event of a humanoid. This avoids the problem with your code, as whenever the humanoid is hit, the code is executed.

2 comments

0

Oh yeah BTW use code blocks

0

Oh, i just discovered this helping page today but thanks for helping me now i understand what i did wrong :D

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