Repeat seems to only be repeating once

I was trying to make a pickaxe for my mining system, but for some reason this repeat thing inside the server code for the pickaxe only repeats once, I am trying to make it repeat the whole way through the time, but it only repeats once and just stops, I have tried to change the until part of the code, but it still doesn’t seem to work.

local function StartMining()
	local Ore = script.Parent.Target.Value
	if DB then
		if Ore then
			if Ore:IsDescendantOf(workspace.Mine) then
				local Distance = (Ore.Position - Player.Character.PrimaryPart.Position).Magnitude
				if Distance > PickStats.Range * 6 then
					return false
				end
				local RealOre = game.ReplicatedStorage.Ores:FindFirstChild(Ore.Name)
				local TimeToMine = (RealOre.Strength.Value/PickStats.Power)
				local CurrentTime = 0

				DB = false
				spawn(function()
					wait(TimeToMine + PickStats.Delay)
					DB = true
				end)

				Player.PlayerGui.ScreenGui.Progress.Visible = true
				repeat 
					wait(0.01) 
					CurrentTime = CurrentTime + 0.01
					print(CurrentTime)
					Player.PlayerGui.ScreenGui.Progress.Frame.Size = UDim2.new(CurrentTime/TimeToMine,0,1,0)
					Player.PlayerGui.ScreenGui.Progress.Frame.BackgroundColor3 = Ore.Color
					Player.PlayerGui.ScreenGui.Progress.TextLabel.Text = Ore.Name
					Player.PlayerGui.ScreenGui.Progress.TextLabel.TextColor3 = Ore.Color
					Player.PlayerGui.ScreenGui.Progress.Icon.Text = Ore:WaitForChild("Icon").Value
					if Ore:FindFirstChild("Icon2") then
						Player.PlayerGui.ScreenGui.Progress.Icon2.Text = Ore:WaitForChild("Icon2").Value
					else
						Player.PlayerGui.ScreenGui.Progress.Icon2.Text = ""
					end
					Player.PlayerGui.ScreenGui.Progress.Icon.TextColor3 = Ore.Color
					Player.PlayerGui.ScreenGui.Progress.Icon2.TextColor3 = Ore.Color

				until CurrentTime >= TimeToMine or not MouseDown or Ore ~= script.Parent.Target.Value

				if (CurrentTime >= TimeToMine) then
					game.ReplicatedStorage.MineOre:Fire(Player,Ore)
				end
				wait(PickStats.Delay)
				DB = true
				if MouseDown then
					StartMining()
				else
				end
			else
				wait()
				if MouseDown then
					StartMining()
				end
			end
		end
	end
end

Does anyone know what’s wrong? I’d greatly appreciate it.

Did you do any basic debugging yet?

print(CurrentTime >= TimeToMine, not MouseDown, Ore ~= script.Parent.Target.Value)

Put that above the until line, if any of them are true the loop should end. If any of them are true but shouldn’t be, then step 1 of debugging is complete. Next, figure out why it’s true.

Nevermind, I managed to fix it just by setting the MouseDown variable to true at the beginning.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.