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

if a union reaches 0 on the health bar. It disappears and an old union spawns in. It doesn't work?

Asked by
jjjona1 -1
2 years ago

I was trying to make if a union reaches 0 on the health bar. It disappears and an old union spawns in.

  local ClickDetector = game.Workspace.Union.ClickDetector
  local Textlabel = game.Workspace.Union.BillboardGui.TextLabel
  local OldUnion = game.ServerStorage:WaitForChild("OldUnion")
  local Union = game.Workspace.Union

  ClickDetector.MouseClick:Connect(function()
      Textlabel.Text = Textlabel.Text - 10
  end)

  if Textlabel.Text == 0 then
      Union.Transparency = 1
      Union.CanCollide = false
      Textlabel.TextTransparency = 1
      OldUnion.Parent = game.Workspace
      OldUnion.CFrame = Union.CFrame

  end 

1 answer

Log in to vote
0
Answered by
enes223 327 Moderation Voter
2 years ago

You are trying to minus a number from a string, you gotta make the string a number first,

TextLabel.Text = tonumber(TextLabel.Text) - 10

if tonumber(TextLabel.Text) == 0 then

and it should work as expected.

Ad

Answer this question