Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make this part transparent when it dies?

Asked by
ali7682 17
7 years ago
Edited 7 years ago

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

0
Are you trying to make a players head invisible? SynthetickDev 188 — 7y
0
Please, just please, use code blocks. hiimgoodpack 2009 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
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.

0
Oh yeah BTW use code blocks User#17125 0 — 7y
0
Oh, i just discovered this helping page today but thanks for helping me now i understand what i did wrong :D ali7682 17 — 7y
Ad

Answer this question