I'm trying to loop the code endlessly by using a while true do. Sometimes, when I change the Humanoid's property Health to zero using the Properties, the script works. However if I set my health to a higher number, and the health is drained using another script, until it reaches 0, nothing happens.
while true do if script.Parent.Humanoid.Health == 0 then local a = Instance.new("Message") a.Text = "The base has been destroyed. You have failed." a.Parent = game.Workspace wait (4) a:remove() end end
I have a separate script in the same model "Base", to give the Humanoid more than 100 health. Here is that script. It's called HumanoidHealth
script.Parent.Humanoid.Health = 10 wait (1) script.Parent.HumanoidHealth:Destroy()
Another way I do it is like this
script.Parent.Humanoid.Changed:connect(function() if script.Parent.Humanoid.Health==0 then local a = Instance.new("Message", workspace) a.Text = "The base has been destroyed. You have failed." game.Debris:AddItem(a, 4) end end)
This way it doesn't constantly check. It will check only when the Humanoid has been changed (Maybe the Health)
You added a 4 second wait, that will slow things down alot. Debris is EXTREMELY useful when it comes to waiting to remove things in loops.
while wait() do if script.Parent.Humanoid.Health == 0 then local a = Instance.new("Message", game.Workspace) a.Text = "The base has been destroyed. You have failed." game.Debris:AddItem(a, 4) end end