Why won't "enemy.health <' work?

I’m making a game that has a boss fight. once you get the boss below a certain health a door is meant to disappear allowing you to leave. What usually happens instead is that it disappears once the server starts or once the criteria is met the door doesn’t go away. I’ve tried many different things such as putting the script in server script service, putting inside of the part going away, putting inside the boss, using :destroy() and turning off can collide and making it transparent but none of them have worked.
This is the code I’m currently using: (texture and texturei are textures on the part)

	game.Workspace.Walls.Door.CanCollide = false
	game.Workspace.Walls.Door.Transparency = 1
	game.Workspace.Walls.Door.Texturei.Transparency = 1
	game.Workspace.Walls.Door.Texture.Transparency = 1
end
16 Likes

If your enemy has a humanoid parented inside it, consider using enemy.Humanoid.Health instead, but if you have a numbervalue/intvalue/etc. parented inside the enemy, you should use enemy.VALUE_OBJECT.Value

If you can tell me where the health is stored then I can help your further and more easily. You can try using print("message") to see if once the boss should count as defeated to see if it registers that it was defeated, or you can use the output to spot any errors.

5 Likes

All I see is that there is a model and in the model there is an enemy.

4 Likes

And no humanoid or bool value?

3 Likes

2 Likes

This is all of the things inside the boss model

2 Likes

please just make a var for the door

local Door = workspace.Walls.Door
4 Likes

updated:

local door = game.Workspace.Walls.Door
if game.Workspace.boss.Enemy.health < 500.1 then
	door.CanCollide = false
	door.Transparency = 1
	door.Transparency = 1
	door.Transparency = 1
end
1 Like

and are you sure the boss’s health isn’t less than 500.1

1 Like

The only thing I’ve got is the casing of Health but then why is it not erroring? (or it might be and you dont know how to open the output window View>Output)

Its Health not health, and consider the <= operator which means less-or-equal to

2 Likes

Yes, I’ve played it and most times I kill the boss and it doesn’t go away.

1 Like

I’ve looked at the output window and it doesn’t error for some reason

3 Likes

Oh wait I know whats wrong.

You’ll need to listen to each time the health is updated before running the comparison.

Whats currently happening is that the script runs, checks if health is lower than 500.1 (it isn’t) and then stops running.

The game doesn’t know you want it to check it every time health changes.

The solution? GetPropertyChangedSignal. You should do something like this to run code every time the health changes (stuff inside the function bit is run every time health changes)

Enemy:GetPropertyChangedSignal("Health"):Connect(function()
  local health = Enemy.Health
  if health <= 500 then
    -- door code goes here
  end
end)

Thanks. It worked. The textures didn’t go away but the transparency became 1 and the door became can collide false.

If you want to make a texture disappear just do

part.Texture.Transparency = 1

I just realized that when I made the door variable I accidentally deleted the .texture and .texturei parts of it.

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