Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When killed, a model will display a message and then delete another model?

Asked by 9 years ago

x = script.Parent.Parent.Terminal

   if script.Parent.Humanoid.Health < 1 then
                  msg = Instance.new("Message")
                  msg.Parent = game.Workspace
                  msg.Text = "The (Team Name) Has Won!"
                  x:remove()
                  wait(5)
                  msg:remove()
                  script.Parent:remove()
     end

Alright, so here is my intent for this script. This is inside a model with a humanoid. When the humanoid's health gets to 0, I'm trying to make it display a message saying a certain team has won, and then it is supposed to delete a similar model that has a different name. For some reason, though, this isn't happening when make it's health 0. Can someone explain why?

0
Are you looping this or using the Humanoid.HealthChanged event to check if the health is less than 1? Also it would be easier to use the Humanoid.Died event instead of those but not required. jakedies 315 — 9y
0
Thanks for the help. I've got a bit of experience with re-purposing scripts and I can write very basic things from scratch, but I'm trying to expand into more advanced areas. profGRob 5 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

You were only checking once to see if the health was less than 1. I also optimized some of your other code.

local x = script.Parent.Parent.Terminal
script.Parent.Humanoid.Died:connect(function()
               msg = Instance.new("Message",Workspace)
               msg.Text = "The (Team Name) Has Won!"
               x:Destroy()
               Game.Debris:AddItem(msg,5)
               wait(5)
               script.Parent:remove()
  end)

Ad

Answer this question