I want a gui to appear when i click on a block

i am making a mining system and i made the health bar of the block / gui and i want it to show up when i mine
and when you click on a diffrent block i want it to switch the gui to a diffrent block here is what i made

Tool.Activated:Connect(function()
	local TimeBetweenHit1 = tick()
	local Time = math.abs(TimeBetweenHit1 - TimeBetweenHit2)
	if Time > 0.5 then
		local MouseT = Mouse.Target.Parent
		if LastPart == nil then
			LastPart = MouseT

			MouseT.Health.BillboardGui.Enabled = true

			task.wait(1)


			MouseT.Health.BillboardGui.Enabled = false
			
			LastPart = nil
		else
			
			
			LastPart.Health.BillboardGui.Enabled = false
			
			LastPart = MouseT
			

			MouseT.Health.BillboardGui.Enabled = true 
			
			
		end


	end
end)

the problem is that it is not disabling the gui so it looks like this

image

Simplified GUI Handling

Tool.Activated:Connect(function()
	local TimeBetweenHit1 = tick()
	local Time = math.abs(TimeBetweenHit1 - TimeBetweenHit2)
	
	if Time > 0.5 then
		local MouseT = Mouse.Target.Parent
		
		if LastPart then
			LastPart.Health.BillboardGui.Enabled = false
		end
		
		LastPart = MouseT
		
		MouseT.Health.BillboardGui.Enabled = true 
		
		TimeBetweenHit2 = TimeBetweenHit1
	end
end)
1 Like

i want it to disable after a certain period of time