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