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

Script only works one time?

Asked by 8 years ago

Below works and all but it only works one time for some reason. Basically what it does it checks if something that touches it is a zombie and if it is it loses health from the zombie by -1 from a value that is displayed on a GUI. For some reason it subtracts 20 from it but when the zombie touches it again nothing happens.

function onTouch(part) 
    local h = part.Parent:FindFirstChild("Zombie torso")


wait(3)
    if h~=nil then
             for i, v in ipairs(game.Players:GetChildren()) do
      local n = v.PlayerGui.Notice.Box.Health1.Health.Value
                n = (n -20)
                v.PlayerGui.Notice.Box.Health1.Text = n
              game.StarterGui.Notice.Box.Health1.Text = n



     end
end
end

script.Parent.Touched:connect(onTouch)

0
Why are you changing the gui in startergui if it's a health gui? Ryzox 220 — 8y
0
@Ryzox so if they die they will see it CorruptBullet 5 — 8y

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

Because of this line local n = v.PlayerGui.Notice.Box.Health1.Health.Value your script only subtracts 20 once.

In the script, you never subtract 20 from the value.

local healthVal = v.PlayerGui.Notice.Box.Health1.Health

healthVal.Value = healthVal.Value - 20 --Subtract from value and set new value


-- Change Text to healthvalue
v.PlayerGui.Notice.Box.Health1.Text = healthVal.Value
game.StarterGui.Notice.Box.Health1.Text = healthVal.Value

0
YOUR A LIFE SAVER CorruptBullet 5 — 8y
Ad

Answer this question