Expected "end" (to close "then" at line 6) got <eof>; did you forget to close "then" at line 27?

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

Every time you make this, a scope is made. To close the scope, use end.

Edit:
Actually, why don’t you explain what you’re trying to do here?

1 Like
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
1 Like

It’s supposed to change the face back to the normal face texture if the health regenerates above 85

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
1 Like

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)
1 Like

SWOOP THERE IT IS

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-
1 Like
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)

tada!

1 Like

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().

1 Like

Thanks for the replies, I will try every single one and see if any of them works.

It was originally there to prevent the script from crashing. But I forgot to delete them after I added “hum.HealthChanged:Connect(function(newHealth)”

@Operatik Your script works perfectly, fits my needs.


@JustAGameDeveloper1 Your first script doesn’t work, has errors.
image


@calvin_coco Your script also works perfectly.


JustAGameDeveloper1 Your updated script also doesn’t work.


@PikachuBoy_YT Your script doesn’t work, it only shows the humanoid dead texture.


Just a disclaimer I’m not trying to shame anyone by saying your script doesn’t work, its the thought that counts. Thanks for replying to this topic.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.