I’m finding if I move between a bunch of blocks, and then focus on one, that 1 block will destory quicker than it should.
-- Start mining the block
local function StartMining(input)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Tool = Character:FindFirstChildWhichIsA("Tool")
local Humanoid = Character:FindFirstChild("Humanoid")
if not Humanoid then return end
local Model = GetRay(input)
if not Model then return end
local BlockData = ItemData[Model.Name]
if not BlockData then return end
local MiningTime = BlockData.Time.Default
CurrentObject = Model
-- Check for tool
if Tool then
if ItemData[Tool.Name].Type == "Block" then return end -- Can't mine with Block
if ItemData[Tool.Name].Type == "Tool" then
if ItemData[Tool.Name].Category == BlockData.ToolCategory then
-- Correct tool for this block type
MiningTime = BlockData.Time[ItemData[Tool.Name].Material]
end
end
end
if Mining then return end
Mining = true
if BlockData.Type == "Block" then
-- Blocks have crack
CreateCrack(CurrentObject.Block)
UpdateCracks(CurrentObject.Block, MiningTime)
end
while Mining do
print("Start", MiningTime) -- Always prints 5
wait(MiningTime)
if not Mining then break end -- Stopped mining
if CurrentObject ~= Model then return end -- Changed models between CurrentObject
DestroyBlock:FireServer(CurrentObject)
if CurrentObject then
CurrentObject:Destroy()
CurrentObject = nil
end
end
Mining = false
end
local function InputBegan(input, GPE)
if GPE then return end
if input.UserInputType ~= Enum.UserInputType.MouseButton1 and input.UserInputType ~= Enum.UserInputType.Touch then return end
StartMining(input)
end
local function InputEnded(input)
if input.UserInputType ~= Enum.UserInputType.MouseButton1 and input.UserInputType ~= Enum.UserInputType.Touch then return end
Mining = false
if CurrentObject then
DestroyCrack(CurrentObject.Block)
CurrentObject = nil
end
end
local function TargetChanged(input)
if not Mining then return end
if input.UserInputType ~= Enum.UserInputType.MouseMovement then return end
local Model = GetRay(input)
if not Model then return end
if Model == CurrentObject then return end -- Same block
if CurrentObject then -- Previous block exists
DestroyCrack(CurrentObject.Block)
CurrentObject = nil
end
Mining = false
-- New object, restart
StartMining(input)
end
UserInputService.InputBegan:Connect(InputBegan)
UserInputService.InputEnded:Connect(InputEnded)
-- Mouse moved
UserInputService.InputChanged:Connect(TargetChanged)
My goal is, to be basically identical in how minecrafts mining works. You have to hold click on a block to stay mining it. If you move off the block, it’ll start mining whatever block you moved onto.
Video of it working
However, sometimes it’ll break before the crack images have finished. It seems to be if I start mining it a bit, then stop, then come back, it’s like it picks back where it left off (which it shouldn’t)