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

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

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)

4 comments

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?

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.

0

There is an existing signal of Humanoid that matches your criteria: HealthChanged

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".

2 answers

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?

2 comments

0

The parental argument of the Instance constructor was deprecated, the best practice is to set the parent manually after all property modifications.

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

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!

1 comment

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.

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