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

How do I detect if the players health is 92 or lower?

Asked by 4 years ago

Hi, I am trying to make a blood/gore script for my friend to use, and something's not working. Could you give me any advice?

if script.Parent.Humanoid.Health <= 92 then
    script.Parent["Left Leg"].Instance.new("Decal")
    script.Parent["Left Leg"].Decal.Texture = "http://www.roblox.com/asset/?id=508050906"
    script.Parent["Left Leg"].Decal.Face = Region3int16
end

(The script is supposed to be in StarterCharacterScripts)

0
Does it have a function? like 'Player.Character.Humanoid.Health.Changed:Connect(Function()' Obviously that probably wont work cause i made it out of studio, but my point is, do you have something making it check? Galaxybombboy 134 — 4y
0
It's formally known as an RBXScriptSignal, or among the CS community, an Event; we bind callbacks to these for preforming actions upon these signals firing. Ziffixture 6913 — 4y
0
There is an existing signal of Humanoid that matches your criteria: HealthChanged Ziffixture 6913 — 4y
0
@TTChaos I'm fairly new to scripting, and when I went to configure which side the Decal would be facing, I put in "Front", but then it gave an autocorrection, which was "Region3int16". KneeDeepInTheDoot 13 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

Like Ziffixture said, You can use Humanoid.HealthChanged to detect when your health is low

local Humanoid = script.Parent.Humanoid -- Get the humanoid
local GoreDecal -- Localize GoreDecal

Humanoid.HealthChanged:Connect(function(Health)
    if Health <= 92 then
        -- script.Parent["Left Leg"].Instance.new("Decal") is wrong, replace with
        GoreDecal = Instance.new("Decal", script.Parent["Left Leg"]) -- which makes a new decal and sets it
        GoreDecal.Texture = "rbxassetid://508050906" -- Use rbxassetid://
        GoreDecal.Face = Region3int16
    end
end)

But I have one question. Why would you set the decal's face to Region3int16?

0
The parental argument of the Instance constructor was deprecated, the best practice is to set the parent manually after all property modifications. Ziffixture 6913 — 4y
1
@Ziffixture if you are the admin, can you please guide the javascript scripters to add, that, you comment on someone's question and the asker replies it, the one who sent the comment before will get the notification of it BestCreativeBoy 1395 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Well, the easiest answer for your question is to add a while loop to check the loop in intervals.

while wait() do -- Loops the code 33 times a sec
    if script.Parent.Humanoid.Health <= 92 then
        script.Parent["Left Leg"].Instance.new("Decal")
        script.Parent["Left Leg"].Decal.Texture = "http://www.roblox.com/asset/?id=508050906"
        script.Parent["Left Leg"].Decal.Face = Region3int16
    end
end

Lemme know if it helps!

0
No. You should know better by now not to do this. Events are there for a reason, so the answer provided an hour ago is already the best answer. SteamG00B 1633 — 4y

Answer this question