local function P_CounterGuardBuffTimer(player)
local pData = game.ReplicatedStorage.PlayerData:FindFirstChild(tostring(player.UserId))
if pData then
pData.Stats.P_CounterGuardBuff.Value = 0
pData.Stats.BlockScaler.Value = pData.Stats.BlockScaler.Value + pData.Stats.UnyieldingBastion.Value
pData.Stats.P_CounterGuardBuff.Value = 15 + (pData.Stats.UnyieldingBastion.Value * 2)
for i = pData.Stats.P_CounterGuardBuff.Value, 0, -0.5 do
pData.Stats.P_CounterGuardBuff.Value = i
wait(0.5)
end
pData.Stats.P_CounterGuardBuff.Value = 0
pData.Stats.BlockScaler.Value = pData.Stats.BlockScaler.Value - pData.Stats.UnyieldingBastion.Value
end
end
When the player uses the ability again it doesn’t restart the counter to count down the player’s value. It creates sorta like a 2nd loop and they are competing with each other. How would I make it so it restarts the counter?
local debounce: boolean, canStop: boolean = false, false
local function P_CounterGuardBuffTimer(player)
debounce = true
local pData = game.ReplicatedStorage.PlayerData:FindFirstChild(tostring(player.UserId))
if pData then
pData.Stats.P_CounterGuardBuff.Value = 0
pData.Stats.BlockScaler.Value = pData.Stats.BlockScaler.Value + pData.Stats.UnyieldingBastion.Value
pData.Stats.P_CounterGuardBuff.Value = 15 + (pData.Stats.UnyieldingBastion.Value * 2)
for i = pData.Stats.P_CounterGuardBuff.Value, 0, -0.5 do
pData.Stats.P_CounterGuardBuff.Value = i
for timeout = .1, .5, .1 do
if debounce then
debounce, canStop = false, true
break
end
task.wait(.1)
end
if canStop then
canStop = false
break
end
end
pData.Stats.P_CounterGuardBuff.Value = 0
pData.Stats.BlockScaler.Value = pData.Stats.BlockScaler.Value - pData.Stats.UnyieldingBastion.Value
end
end