I am making a system where you drill through a safe. Currently, the drill has a small chance to break. If the chance succeeds, the player must fix the drill.
The problem is that even after the drill is fixed, it does not continue the countdown.
Code:
function Countdown(Time, Display)
local CurrTime = Time
local Drilling = true
local DoneDrilling = false
local TimesBroken = 0
local BreakChance = CurrSessionInfo.DrillBreakChance
local MaxBreaks = CurrSessionInfo.MaxDrillBreaks
while Drilling do
CurrTime = CurrTime - 1
Display.Text = (CurrTime .. " SECONDS")
if CurrTime <= 0 then
print("Drill finished!")
DoneDrilling = true
Drilling = false
return true
else
local RandVal = math.random(1, 100)
if RandVal <= BreakChance.Value and TimesBroken < MaxBreaks.Value then
print("Drill broken!")
TimesBroken = TimesBroken + 1
Drilling = false
local Prompt = Instance.new("ProximityPrompt")
Prompt.Parent = Display.Parent.Parent.Parent.Parent.PrimaryPart
Prompt.RequiresLineOfSight = false
Prompt.MaxActivationDistance = 14
Prompt.ActionText = ("Restart")
Prompt.ObjectText = ("Drill")
Prompt.HoldDuration = 4
local Sound = Display.Parent.Parent.Parent.Broken
Sound:Play()
Prompt.Triggered:Connect(function()
print("Drill fixed!")
Prompt:Destroy()
Sound:Stop()
Drilling = true
end)
end
end
task.wait(1)
end
end
I don’t quite understand how to implement this. This is the modified code I tried to use, and it’s not quite working:
function Countdown(Time, Display)
local CurrTime = Time
local Drilling = true
local DoneDrilling = false
local TimesBroken = 0
local BreakChance = CurrSessionInfo.DrillBreakChance
local MaxBreaks = CurrSessionInfo.MaxDrillBreaks
while true do
local RandVal = math.random(1, 100)
if RandVal <= BreakChance.Value and TimesBroken < MaxBreaks.Value then
print("Drill broken!")
TimesBroken = TimesBroken + 1
Drilling = false
local Prompt = Instance.new("ProximityPrompt")
Prompt.Parent = Display.Parent.Parent.Parent.Parent.PrimaryPart
Prompt.RequiresLineOfSight = false
Prompt.MaxActivationDistance = 14
Prompt.ActionText = ("Restart")
Prompt.ObjectText = ("Drill")
Prompt.HoldDuration = 4
local Sound = Display.Parent.Parent.Parent.Broken
Sound:Play()
Prompt.Triggered:Connect(function()
print("Drill fixed!")
Prompt:Destroy()
Sound:Stop()
Drilling = true
end)
repeat task.wait(1) until Drilling
while Drilling do
CurrTime = CurrTime - 1
Display.Text = (CurrTime .. " SECONDS")
if CurrTime <= 0 then
print("Drill finished!")
DoneDrilling = true
Drilling = false
return true
end
task.wait(1)
end
end
end
task.wait(1)
end
It always instantly breaks the drill upon being placed, and then never breaks the drill again.
Make a variable for the remaining time and break out of the loop. Once you want to start it back up again, just take that variable and make a new for loop with it.