( I wasn’t sure what to name the topic)
I am working on a boss battle for my game. I’m trying to make an event happen when the boss’s health reaches 0. For some reason this script below doesn’t work. Where did I go wrong?
local BossHealth = game.Workspace.Boss.Humanoid.Health
if BossHealth = 0 then
print (“Boss is dead”)
end)
You should instead do
local BossHealth = game.Workspace.Boss.Humanoid
BossHealth.Died:Connect(function()
print (“Boss is dead”)
end)
4 Likes
Try doing what the player health script does, it checks to see if the health is below 1. It might not be working because the health is -1 or something.
EDIT: This would look something like:
local BossHealth = game.Workspace.Boss.Humaniod.Health
if BossHealth < 1 then
print("Boss is dead")
end
The main issue seems to be that, instead of using the equality operator (==
) you assign BossHealth
to 0
.
Assuming that was just an oversight of typing that code into the forums, there’s a logical error. I assume you don’t want to check just once when that script is executed. Do what @MarshyloI does and connect an event handler to the event Humanoid.Died
(I would quote his answer, but due to the formatting errors here it is already formatted):
local bossHumanoid = workspace.Boss.Humanoid;
local function onBossDeath()
print("The boss has died!");
end
bossHumanoid.Died:connect(onBossDeath);
3 Likes