How can I do this?

how can I make it you hold a block and a visual effect comes up which is a tween the part slowly turns black until it breaks? Each block has a “BreakTime” value.

how can I also not make it overlap and stuff, and disappear when not hovering over that part anymore.

while task.wait(1/60) do
	pcall(function()
		local Target = Mouse.Target
		
		
		
		if HoldingMB1 then
			
			if check(Target) then -- checks if the target is a block

				
				CurrentProgress+=1/60
				if CurrentProgress>=Target.BreakTime.Value then
					print("Break.")
					CurrentProgress = 0
					Target:AddTag("Broken")
					Target.RemoteEvent:FireServer() -- breaks the block		
				end
				
			end
			
		end

	end)

end

I figured it out

while task.wait(1/60) do
	pcall(function()
		local Target = Mouse.Target
		GlobalTarget = Target
		
		
		
		if HoldingMB1 then
			
			if Target~=BeforeTarget then
				if check(BeforeTarget) then
					BeforeTarget:RemoveTag("Hovering")
					CurrentProgress = 0
				end
			end
			
			if check(Target) then
				CurrentMTarget = Target
				if Target==BeforeTarget and not Target:HasTag("Hovering") then
					Target:AddTag("Hovering")
					local t = game.TweenService:Create(Target,TweenInfo.new(Target.BreakTime.Value+.5,Enum.EasingStyle.Linear),{Color = Color3.new(0,0,0)})
					t:Play()
					task.spawn(function()
						repeat
							task.wait()
						until GlobalTarget~=Target
						if t then
							t:Pause()
							t:Destroy()
							if Target.Parent~=nil then
								local defC = Target:FindFirstChild("DefaultColor")
								
								if defC then
									Target.Color = Target.DefaultColor.Value
								end
							end
							
						end
					end)
					
				end

				
				CurrentProgress+=1/60
				if CurrentProgress>=Target.BreakTime.Value then
					print("Break.")
					CurrentProgress = 0
					Target:AddTag("Broken")
					Target.RemoteEvent:FireServer()
				end
				
			end
			
			BeforeMTarget = Target
		end

		
		HoldingMB1Before = HoldingMB1
		BeforeTarget = Target

	end)

end

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