I’m not the best scripter, but I’ve been trying to make a script that changes the face of a character depending on the HP they’re on. But I can’t figure out what’s wrong with it. I’ve tried adding more ends which did clear the error but made it so it didn’t even work.
Help?
local hum = script.Parent.Humanoid
hum.HealthChanged:Connect(function(NewHealth)
if NewHealth <= 86 then
script.Parent.Head.face.Texture = "rbxasset://textures/face.png"
task.wait(1)
if NewHealth >= 85 then
local texture1 = "rbxassetid://11662434015"
script.Parent.Head.face.Texture = texture1
task.wait(1)
if NewHealth >= 40 then
local texture2 = "rbxassetid://11663458229"
script.Parent.Head.face.Texture = texture2
task.wait(1)
end
if hum.Died then
local texture3 = "rbxassetid://11663905589"
script.Parent.Head.face.Texture = texture3
end
end
local hum = script.Parent.Humanoid
hum.HealthChanged:Connect(function(NewHealth)
if NewHealth <= 86 then
script.Parent.Head.face.Texture = "rbxasset://textures/face.png"
task.wait(1)
if NewHealth >= 85 then
local texture1 = "rbxassetid://11662434015"
script.Parent.Head.face.Texture = texture1
task.wait(1)
if NewHealth >= 40 then
local texture2 = "rbxassetid://11663458229"
script.Parent.Head.face.Texture = texture2
task.wait(1)
end
if hum.Died then
local texture3 = "rbxassetid://11663905589"
script.Parent.Head.face.Texture = texture3
end
end
end
Perhaps this would fix the technical issue and to the described behavior you intended?
local hum = script.Parent.Humanoid
hum.HealthChanged:Connect(function(newHealth)
if newHealth > 85 then
script.Parent.Head.face.Texture = "rbxasset://textures/face.png"
task.wait(1)
elseif newHealth > 40 then
local texture1 = "rbxassetid://11662434015"
script.Parent.Head.face.Texture = texture1
task.wait(1)
elseif newHealth > 0 then
local texture2 = "rbxassetid://11663458229"
script.Parent.Head.face.Texture = texture2
task.wait(1)
else
local texture3 = "rbxassetid://11663905589"
script.Parent.Head.face.Texture = texture3
end
end) -- woops forgot to close it
You forget the end) for this part and I’m pretty sure those are supposed to be elseif. Also, what’s the point of waiting?
local hum = script.Parent.Humanoid
hum.HealthChanged:Connect(function(NewHealth)
if NewHealth > 80 then -- It wont work if it's <= (probably)
script.Parent.Head.face.Texture = "rbxasset://textures/face.png"
elseif NewHealth > 40 then
local texture1 = "rbxassetid://11662434015"
script.Parent.Head.face.Texture = texture1
elseif NewHealth > 0 then
local texture2 = "rbxassetid://11663458229"
script.Parent.Head.face.Texture = texture2
elseif hum.Health == 0 then -- No, Hum.Died is an event not a boolean.
local texture3 = "rbxassetid://11663905589"
script.Parent.Head.face.Texture = texture3
end
end)
local hum = script.Parent.Humanoid
hum.HealthChanged:Connect(function(NewHealth)
if NewHealth <= 86 then
script.Parent.Head.face.Texture = "rbxasset://textures/face.png"
task.wait(1)
if NewHealth >= 85 then
local texture1 = "rbxassetid://11662434015"
script.Parent.Head.face.Texture = texture1
task.wait(1)
if NewHealth >= 40 then
local texture2 = "rbxassetid://11663458229"
script.Parent.Head.face.Texture = texture2
task.wait(1)
end
if hum.Died then
local texture3 = "rbxassetid://11663905589"
script.Parent.Head.face.Texture = texture3
end
end
end
end) --END-
local hum = script.Parent.Humanoid
hum.HealthChanged:Connect(function(NewHealth)
if NewHealth <= 86 then
script.Parent.Head.face.Texture = "rbxasset://textures/face.png"
task.wait(1)
if NewHealth >= 85 then
local texture1 = "rbxassetid://11662434015"
script.Parent.Head.face.Texture = texture1
task.wait(1)
if NewHealth >= 40 then
local texture2 = "rbxassetid://11663458229"
script.Parent.Head.face.Texture = texture2
task.wait(1)
end
end
if hum.Died then
local texture3 = "rbxassetid://11663905589"
script.Parent.Head.face.Texture = texture3
end
end
end)
Just make sure that when you want to end an if statement (or a while, for, etc.) that you use end when you want to stop whatever is supposed to happen only when the statement can run. From what it looks like, you need ends for each if NewHealth >= x then statements before the next one of those. Sorry if this is confusing.
Just wanted to mention that your script won’t do anything if the health x is 85<x<86 because that isn’t included in the range that the script detects.
Also, for a somewhat new scripter, good job on using task.wait(). I find it very hard to remember to do that instead of just wait().