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

Script only works one time?

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)

2 comments

0

Why are you changing the gui in startergui if it's a health gui?

0

@Ryzox so if they die they will see it

1 answer

✓ Accepted answer

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

1 comment

0

YOUR A LIFE SAVER

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