-
What do you want to achieve?
It’s simple, but I am out of ideas. I want to restart a loop/the timer everytime the Text from the TextLabel updates. I am converting the string into a number so that won’t be the problem.
Description:
Everytime a player hits another player, an event (Bleed) is fired and connects in this script where it increases the number of bleed by 0.5 which works, and makes the bleed icon visible. Moreover I want the bleeding to stop after the amount of bleed decreases by one until it hits 0. If it hit zero the timer/loop will break, and the icon becomes invisible.
-
What is the issue?
The timer does not reset properly, since 10 is currently set as default it just counts down from 10. After 10 seconds the icon disappears. Though I want it so if the player is being hit and the number next to the icon increases by or ends at let’s say 18, I want the timer to count down from 18 and then make the icon invisible. -
What solutions have you tried so far?
YouTube, other DevForum posts
What it looks like:
-- Increase Bleed ---
game.ReplicatedStorage.Bleed.OnClientEvent:Connect(function()
script.Parent.Visible = true
BleedEnabled()
end)
--Functions --
function BleedEnabled()
script.Parent.Amount.Text = tonumber(script.Parent.Amount.Text) + 0.5
local BleedAmount = tonumber(script.Parent.Amount.Text)
local player = game.Players.LocalPlayer
local hum = game.Workspace:WaitForChild("Characters"):WaitForChild(player.Name):WaitForChild("Humanoid")
local timer = BleedAmount;
coroutine.wrap(function()
while hum.Health > 0 do -- loop until the player dies
repeat
wait(1);
timer -= 1;
until timer <= 0;
script.Parent.Visible = false
timer = BleedAmount;
end
end)()
script.Parent.Amount:GetPropertyChangedSignal("Text"):Connect(function()
local NewTimer = tonumber(script.Parent.Amount.Text)
timer = BleedAmount
if BleedAmount >= 0 then
script.Parent.Visible = true
end
end)
end