Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

2 comments

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.

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.

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.