I'm trying to make a script so that when you get hurt your face changes for a little time, but I can't get it work. The script is a script inside StarterCharacterScripts, and It's the following:
local previousface = script.Parent.Head.face.Texture local humanoidhealth = script.Parent.Humanoid.Health if humanoidhealth > script.Parent.Humanoid.Health then script.parent.Head.face.Texture = "rbxassetid://732910174" wait (0.5) script.parent.Head.face.Texture = previousface local humanoidhealth = script.Parent.Head.face.Texture end if humanoidhealth < script.Parent.Humanoid.Health then local humanoidhealth = script.Parent.Humanoid.Health end
I can't get what's wrong. The first if then is for changing the face when you get hurt. The second one is for setting humanoidhealth to the humanoids health if it rehealhs.
Help!
Your script is checking the health of the character immediately when it begins to execute when it should be running a block of code every time the character's health changes. In order to do this, you can use the HealthChanged
event of the humanoid.
local previousface = script.Parent.Head.face.Texture local humanoid = script.Parent:WaitForChild("Humanoid") local humanoidHealth = humanoid.Health humanoid.HealthChanged:Connect(function(newHealth) if newHealth < humanoidHealth then script.parent.Head.face.Texture = "rbxassetid://732910174" wait (0.5) script.parent.Head.face.Texture = previousface end humanoidHealth = newHealth end)