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

How Do I Make a part visible if a player reaches a certain health?

Asked by
VVoretex 146
3 years ago

I've been making a game where when you reach say, 75 health or less, blood will appear. Here is the script:

if script.Parent.Parent:WaitForChild("Humanoid").Health == 0 then
    script.Parent.Parent.Knife.Transparency = 0
end
if script.Parent.Parent:WaitForChild("Humanoid").Health <= 25 then
    script.Parent.Parent.Blood.Decal.Transparency = 0
    script.Parent.Parent.Blood.Decal2.Transparency = 0
end
if script.Parent.Parent:WaitForChild("Humanoid").Health <= 75 then
    script.Parent.Parent.Blood2.Decal.Transparency = 0
end
0
1 script.Parent.Parent:WaitForChild("Humanoid").HealthChanged:Connect(function(health) 2 if health == 0 then -- put what health you want to detect here 3 --code here 4 end 5 end) DanielPlays2468 0 — 3y
0
h DanielPlays2468 0 — 3y

2 answers

Log in to vote
0
Answered by
Dexiber 272 Moderation Voter
3 years ago

You can use the event "Health Changed" instead of making a if then statement first.

Here is a format:

script.Parent.Parent:WaitForChild("Humanoid").HealthChanged:Connect(function(health)
if health == 0 then -- put what health you want to detect here
--code here
end
end)

Tell me if this works, try it!

0
oh ok sry for the late respone VVoretex 146 — 3y
0
still doesnt work VVoretex 146 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Try this

script.Parent.Parent:WaitForChild("Humanoid").Changed:Connect(function() --This detects whenever something in the humanoid changes
    if script.Parent.Parent:WaitForChild("Humanoid").Health == 0 then
        script.Parent.Parent.KnifeTransparency = 0
    end
end)

script.Parent.Parent:WaitForChild("Humanoid").Changed:Connect(function()
    if script.Parent.Parent:WaitForChild("Humanoid").Health <= 25 then
        script.Parent.Parent.Blood.Decal.Transparency = 0
        script.Parent.Parent.Blood.Decal2.Transparency = 0
    end
end)

script.Parent.Parent:WaitForChild("Humanoid").Changed:Connect(function()
    if script.Parent.Parent:WaitForChild("Humanoid").Health <= 75 then
        script.Parent.Parent.Blood2.Decal.Transparency = 0
    end
end)

Answer this question