I have a UI (Basically a progress bar for destroying objects) that after each time it is enabled, it will disable itself after 15 seconds.
The problem is that if the player is still destroying things (meaning the progress bar is still being activated), and the 15 seconds have passed, it will keep just de activating and activating on each time until the player stops activating it.
-- the functions aren't related to the progress bar, just other things
event.OnClientEvent:Connect(function(part, minus)
if part:IsA("Terrain") == false then
active = true
local hp:number = UIFunction.GetHp(part)
local maxHp = UIFunction.getMaxHp(part)
if hp then UIFunction.Damage(part, minus, hp) end
UIFunction.UpdateUI(part.Name, maxHp, hp) -- this one just enables it thats it
if hp == 0 then
UIFunction.Finish(part)
end
wait(15)
player.PlayerGui:WaitForChild("BreakingBar").Enabled = false
end
end)
The only thing it does is call the client with the parameters of what part (the part is whatever part is being damaged) and how much damage (which is minus). The server script doesn’t matter tho. All it needs is a way to disable after the last activation, not anything to do with the actual server script and function
I cant understand the whole system with just this script. Try making a bool value called “PartDestroyed” and if the part is destroyed make it set to false. and check if the value is false it makes the gui disabled Im not sure if thats what your going for though.
i think this would work depending on when the function gets fired
-- the functions aren't related to the progress bar, just other things
local currenttimestamp = tick()
event.OnClientEvent:Connect(function(part, minus)
if part:IsA("Terrain") == false then
active = true
local hp:number = UIFunction.GetHp(part)
local maxHp = UIFunction.getMaxHp(part)
if hp then UIFunction.Damage(part, minus, hp) end
UIFunction.UpdateUI(part.Name, maxHp, hp) -- this one just enables it thats it
if hp == 0 then
UIFunction.Finish(part)
end
local timestamp = tick()
currenttimestamp = timestamp
task.delay(function()
if currenttimestamp == timestamp then
player.PlayerGui:WaitForChild("BreakingBar").Enabled = false
end
end
end
end)
I didn’t need to add the task.delay part you could keep the task.wait and I can’t really explain how this works except for the fact that the currenttimestamp variable can be changed throughout the whole script allowing for the timestamp to be different when the 15 seconds of waiting has passed. Since the function only fires whenever you damage the object (I think and if not it would not work) if they stop damaging the part and wait for 15 seconds it should stop and if you damage the part again within the 15 seconds it will reset the timer until the progress bar disables.