Islands like block breaking system?

I want someone to have to hold down MouseButton1 for like 2 seconds in order for the block to be destroyed here is my code right now?

local UserInputService = game:GetService("UserInputService")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")


local Distance = 15
local MouseButton1Down = false

UserInputService.InputBegan:Connect(function(InputBegan)
	if InputBegan.UserInputType == Enum.UserInputType.MouseButton1 then
		MouseButton1Down = true
		while wait() and MouseButton1Down do
			if Mouse.Target then
				Mouse.Target:Destroy()
			end
		end
	end
end)

UserInputService.InputEnded:Connect(function(InputEnded)
	if InputEnded.UserInputType == Enum.UserInputType.MouseButton1 then
		MouseButton1Down = false
	end
end)

No, this code is not going to do what you expect. But you already knew that.

You are checking and destroying the Mouse.Target every iteration of the loop.

I did not ask to be told what I already know. I asked to be told what I don’t know

I said “no” :slight_smile:

You want a solution too?

Only destroy the block at the end of the loop. Make sure the Target has been that same block every frame. Keep track of when the mouse is pressed down, so you can add an if statement checking if the current time is more than 2 seconds later than when they started.